Topic: Jumping out of Nested Do's the right way and request for cleverness

As a test/gettoknowya exercise I'm playing with nested Do loops. My project is 10 deep but for simplicity I'll ask about a 3 deep situation.

I've seen commands "Cycle" and "Exit" and I know what they do within one loop. If I am nested in
A
  B
    C
And I Cycle in C, I know it skips an iteration for C. It seems if I am in B and Cycle out, I skip the iteration for B and ALL of C. Same with A, If I cycle out of A, All of B and C are skipped for that Cycle - Correct?

Now for an Exit, If I Exit in the middle of the increment range of C, I'm still in the loop of B so will come back into C on the next iteration of B - Correct?

So - If I'm in the loop of C and my criteria is meet so I don't need any more looping, what is the best way to exit from the "center" of the three nested Do Loops?

I have read and searched, but most examples deal with simple, 1 tier, cases.

In this exercise, I need to run A, B, and C though numbers 0 thru 9, So I have them nested in Do's, each going from 0 to 9 and a Brute Force visit of possibilities. BUT I ONLY NEED to test a condition with all three indexes are unique.

At this point I have a huge IF statement that check that index A isn't equal to B or C AND B isn't equal to A or C AND C isn't equal to A or B. Is there a more elegant way to run A, B, and C thorough all numbers 0 to 9 but have a cleaner way of testing my condition only when each has a unique value?

In the real situation, I have 10 Do loop indexes and only need to test when all 10 have unique values.
In brute force, it seems like 10 to the power of 10 iterations. It would be nice if I could cut that down by only allowing all ten to take on every value from 0 to 10 but only generate values that are always unique with respect to one another.

Thank you.

Re: Jumping out of Nested Do's the right way and request for cleverness

Here is the code I am playing with. I'm thinking I've been referencing some language definitions that might not match this compiler's syntax. In the example below, right after
IF (i/=o) AND (i/=g) AND (i/=w) AND (i/=y) AND (i/=a) AND (i/=h)  &
the error says I cannot assign a named constant (i) at 1

I get the same error with this statement
IF (Total1 == Liya) And (Total2 == Oyoo) Then

It's as if I defined my variables as integer constants instead of interger variables

Another error that popped up was a missing End Do, but That might be because of those other errors
If I comment out all the IF statements (and End IF) I compile without error.

What is a good source that defines the syntax for this compiler? For example, one book says I have to use .OR. .And. instead of just OR And. Or it says I have to use Integer :: myVar instead of just Integer myVar



Implicit None

! Define the loop variables that run 1 thu 9
! No leading character can be zero
Integer  h, l, s, t

! Define the loop variables that run 0 thru 9
Integer  i, o, g, w, y, a

! Define the variables that make up the equations
Integer  Silo, High, Too, Low, So, Liya, Oyoo

! Define the equation totals
Integer  Total1, Total2

Print *, "Let the games begin"
! Start the zero to nine loops
ix: Do i = 0, 9
! Print the outer most loop to show we have a heart beat
Print *, "i is ", i
    ox: Do o = 0,9
        gx: Do g = 0,9
            wx: Do w = 0,9
                yx: Do y = 0,9
                    ax: Do a = 0,9
! Now the 1 to 9 loops
                        hx: Do h = 1,9
                            lx: Do l = 1,9
                                sx: Do s = 1,9
                                    tx: Do t = 1,9
! Build the Variables
! Only when Indexes are unique
IF (i/=o) AND (i/=g) AND (i/=w) AND (i/=y) AND (i/=a) AND (i/=h)  &
    AND  (i/=l) AND (i/=s) AND (i/=t)  &
    AND  (o/=g) AND (o/=w) AND (o/=y) AND (o/=a) AND (o/=h) AND (o/=l)  &
    AND  (o/=s) AND (o/=t)  &
    AND  (g/=w) AND (g/=y) AND (g/=a) AND (g/=h) AND (g/=l) AND (g/=s)  &
    AND  (g/=t) &
    AND  (w/=y) AND (w/=a) AND (w/=h) AND (w/=l) AND (w/=s) AND (w/=t)  &
    AND  (y/=a) AND (y/=h) AND (y/=l) AND (y/=s) AND (y/=t)             &
    AND  (a/=h) AND (a/=l) AND (a/=s) AND (a/=t)                        &
    AND  (l/=s) AND (l/=t) AND (s/=t) THEN

Silo = o + 10*l + 100*i + 1000*s
High = h + 10*g + 100*i + 1000*h
Too = o + 10*o + 100*t

Low = w + 10*o + 100*l
So = o + 10*s

Liya = a + 10*y + 100*i + 1000*l
Oyoo = o + 10*o + 100*y + 1000*o

! Test the equations

Total1 = Silo + High + Too
Total2 = Silo + Low + So

       IF (Total1 == Liya) And (Total2 == Oyoo) Then

            Print *, "Silo is ", Silo
            Print *, "High is ", High
            Print *, "Too is ", Too
            Print *, "Total is ", Total1
            Print *, "Liya is ", Liya
            Print *, ""
            Print *, "Silo is ", Silo
            Print *, "Low is ", Low
            Print *, "So is ", So
            Print *, "____________________"
            Print *, "Total is ", Total2
            Print *, "Oyoo is ", Oyoo
            Print *, ""
            Print *, "i is ", i, "o is ", o, "g is ", g, "w is ", w, "y is ", y
            Print *, "a is ", a, "h is ", h, "l is ", l, "s is ", s, "t is ", t
            Print *, "Finished"
            Stop
        End IF
    End IF

End Do tx
End Do sx
End Do lx
End Do hx
End Do ax
End Do yx
End Do wx
End Do gx
End Do ox
End Do ix
Print *, "Finished"
Stop
End Program

Re: Jumping out of Nested Do's the right way and request for cleverness

An example of what I'm asking about for a syntax reference is some books show variable declaration as

Integer :: MyVar

While others show just
Integer MyVar

Some references show the logical operators as OR AND and others show them as .OR. .AND.

I've looked at the documentation on the SF support page but can't find what I'm looking for in any of the content headings.

I've googled Fortran References but haven't found one that explains why I'm getting assigning to a named constant errors.

I started out with Fortran IV decades ago and have added that many years working with syntax for PL/1, COBAL, various BASIC compilers, Pascal, and a few others. So when getting back into it, there's a "What does this compiler want it to look like" level I need to know so the syntax becomes more "muscle memory" and I can focus on the algorithm itself.

Re: Jumping out of Nested Do's the right way and request for cleverness

Found It!

I've been reading a lot of .pdf files about Fortran 90 and see some of my confusion was old vs new syntax of Fortran 77 vs Fortran 90.

In the situation above, My IF statement was IF A .and. B and I'm guessing wasn't happy because of "IF A" were it was expecting A to be logical type. So IF (A .and. B) fixed it.

I added back the .AND, instead of just "and" and put back the :: after the Integer type.
But the crux was to appropriately bracket the comparisons in the IF statement  so it was IF (X .AND. Y) instead of IF X .AND. Y