News for hackers. Stuff that matters.
Re:GOTOphobia Considered Harmful (In C) by spacechild1 on Sunday February 26, 2023 @03:30PM (#34949057)
> but true spaghetti code that GOTOs all over the place and is nigh-impossible to follow has been extremely rare for a long time.

Exactly! Recently I had the "pleasure" to work with some FORTRAN IV code from the early 60s, so I know what you mean. No functions/subroutines, only GOTOs. Even loops were done with labels. There is also a weird feature called "arithmetic IF statements" (https://en.wikipedia.org/wiki/Arithmetic_IF). Luckily the code was pretty short (about 500 lines including comments).

Re:GOTOphobia Considered Harmful (In C) by bee_rider on Sunday February 26, 2023 @04:55PM (#34949936)
Hmm, it is time to live Cunningham's Law I think:

There’s no good way to do a do…while loop in Fortran, other than a goto.

Re:GOTOphobia Considered Harmful (In C) by spacechild1 on Sunday February 26, 2023 @06:02PM (#34950633)
Early Fortran already had loops, but with labels:

         INTEGER A(4,4), C, R 
         ... 
         DO 10 WHILE ( C .NE. R ) 
                A(C,R) = A(C,R) + 1 
         C = C+1 
  10     CONTINUE

Note that Fortran has evolved significantly over time. This is how you would write the same in Fortran 77:

       INTEGER A(4,4), C, R 
       ... 
       C = 4 
       R = 1 
       DO WHILE ( C .GT. R ) 
              A(C,R) = 1 
              C = C - 1 
       END DO
Re:GOTOphobia Considered Harmful (In C) by bee_rider on Sunday February 26, 2023 @06:18PM (#34950781)
Those are just regular loops, though, right? I’m looking for the posttest loop, sometimes known as the do…while or until loop. There seems to be a unfortunate inconsistency in the naming of this thing.
Re:GOTOphobia Considered Harmful (In C) by spacechild1 on Sunday February 26, 2023 @07:42PM (#34951559)
Ah, right, I misread your post. DO WHILE is indeed a "normal" while loop. There doesn't seem to be an equivalent to "do { ... } while", as found in most C-style languages.

> There seems to be a unfortunate inconsistency in the naming of this thing.

Well, Fortran is older than C, so you cannot really blame them :-)

Re:GOTOphobia Considered Harmful (In C) by bee_rider on Sunday February 26, 2023 @08:26PM (#34951864)
The funny thing is, I mostly program in Fortran (thus the interest in this construct). It is nice for expressing “this iterative method must be run at least once.” Unfortunately at some point I absorbed the name that comes from the C-ism, haha.
Re:GOTOphobia Considered Harmful (In C) by spacechild1 on Monday February 27, 2023 @04:51AM (#34954659)
May I ask what field you're working in? Physics?
Re:GOTOphobia Considered Harmful (In C) by int_19h on Monday February 27, 2023 @04:58AM (#34954693)
A less ambiguous name for those is repeat/until, as seen in Pascal and its descendants - I don't recall any language that uses that syntax for anything other than a postcondition loop.