-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"do / else" proposal #342
Comments
Just to be clear, the above is equivalent to the below? condition = .false.
do i = 1, 10
...
if (condition) exit
end do
if (i > 10) then
! This block only executes if the do loop doesn't exit.
error stop "Condition not met"
end if |
Yes. I updated the above description with an example. (I don't like using loop variables after the loop, but that's a separate issue: is it even specified by the standard?) |
Yes, although it's not immediately obvious. From 11.1.7.4.3 The execution cycle
and from 11.1.7.4.5 Loop termination
So if a do loop completes all its iteration, the standard says it has a value > the ending value. |
@everythingfunctional thanks for the clarification! |
Looks like syntactic vinegar for the existing and less mysterious
|
https://fortran-lang.discourse.group/t/for-else-or-do-else-in-fortran/8696
Example:
which would be equivalent to:
Similar to Python's "for else": https://docs.python.org/3/tutorial/controlflow.html#else-clauses-on-loops
The text was updated successfully, but these errors were encountered: