I've been teaching myself (modern) Fortran the last few weeks. Just because. It has an interesting behavior that I kind of like.
Normal IF statement: if (something) then <statement 1> <statement 2> end if But it also has a "one line IF" (not sure offhand of the Fortran "name" for this): if (something) <single statement> <single statement> must be on the same line as the if and the condition (unless you specify the "line continuation character"), and of course only one statement is allowed. Kind of like the C/Java if statement with out a statement block, but less dangerous because of the "on the same line" requirement. Here is one way I've used it in practice. call get_command_argument(1, host) if (inet_addr(host) .lt. 0) call error_stop("Host must be in dotted decimal format.") call get_command_argument(2, port_str) read (port_str, '(i5)', iostat = iostat) port ! convert string 'port_str' to integer 'port' if (iostat .ne. 0 .or. port .le. 0) call error_stop("Port must be positive numeric (0-32767).") Using "if/then" instead of just "if" I'd have had this: call get_command_argument(1, host) if (inet_addr(host) .lt. 0) then call error_stop("Host must be in dotted decimal format.") end if call get_command_argument(2, port_str) read (port_str, '(i5)', iostat = iostat) port ! convert string 'port_str' to integer 'port' if (iostat .ne. 0 .or. port .le. 0) then call error_stop("Port must be positive numeric (0-32767).") end if Given by absolute druthers I would have the then clause part of the single line if instead of the if/end if, but its still pretty nice regardless, as it doesn't cause as much "clutter" as error handling often does. On a side note, I think Fortran has done a much better job than COBOL of adding "modern" features (starting with Fortran 90 in 1990). If only the COBOL "designers" had followed in their footsteps. And in my mind Fortran had even more to "make up" for in regards to it's less than ideal beginnings. Which Fortran can even be forgiven for then, being I believe about five years older than COBOL (Cobol?). ________________________________ From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> on behalf of Bob Bridges <robhbrid...@gmail.com> Sent: Sunday, June 7, 2020 12:35 PM To: IBM-MAIN@LISTSERV.UA.EDU <IBM-MAIN@LISTSERV.UA.EDU> Subject: Re: COBOL Question The only language I can think of off-hand that doesn't require some sort of END to close a DO (I'm sure there are others) is ISPF. But, in REXX at least, I never use single-statement DOs. I see them all the time, and I don't get it. Like this: if x=0 then do x=x+1 end Or, more painfully: select when idx="T" then do countt=countt+1 end when idx="U" then do countu=countu+1 end when idx="V" then do countv=countv+1 end when idx="W" then do countw=countw+1 end otherwise do countx=countx+1 end end Why? If it were easier to read, I might sympathize. But it's harder, not easier. --- Bob Bridges, robhbrid...@gmail.com, cell 336 382-7313 /* It's a good thing Lincoln wrote the Gettysburg Address the year that he did, or else that "fourscore and seven years" part would have just been plain wrong. -Paul Paternoster */ -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Paul Gilmartin Sent: Saturday, June 6, 2020 14:40 But in Rexx similarly, END is required even for a single-statement DO. Good for Rexx. I like strong closure. >--- On 6 Jun 2020 10:53:44 -0700, (Bob Bridges) wrote: >>Oh, you need an END-IF even for a single-statement IF? I forgot; I've been >>thinking in REXX too long. In that case you're close; I guess I really meant ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN