Department numbers: Difference between revisions

m
Line 515:
This uses the ability standardised in F90 of labelling a DO-loop so that its start and end are linked by usage of the same name, with this checked by the compiler. Further, in avoiding the use of the dreaded GO TO statement, the CYCLE statement can be employed instead with the same effect, and it too can bear the same name so that it is clear which loop is involved. These names prefix the DO-loop, and so, force some additional indentation. They are not statement labels and must be unique themselves. Notably, they cannot be the same text as the name of the index variable for their DO-loop, unlike the lead given by BASIC with its <code>FOR I ... NEXT I</code> arrangement.
 
The method is jsutjust to generate all the possibilities, discarding those that fail the specified tests. <lang Fortran> INTEGER P,S,F !Department codes for Police, Sanitation, and Fire. Values 1 to 7 only.
PP:DO P = 2,7,2 !The police demand an even number. They're special and use violence.
SS:DO S = 1,7 !The sanitation department accepts any value.
1,220

edits