3

I am working through some code other people have written and found a piece of Fortran syntax that I haven't seen yet and don't exactly understand nor can seem to find anything on the web about (probably because I don't know what it's called).

The code looks like this:

bisection_or_ordering:if(ordering /= 'bisection') then
  ...
  do stuff
  ...
end if bisection_or_ordering

bisection_or_ordering is not a variable and not declared anywhere in the code.

What does this do? What is it for? And what is it called?

mivkov
  • 471
  • 5
  • 19

1 Answers1

5

The part before the colon is a construct name.

Executable constructs with blocks - if, block, associate, critical, select case, select type and of course do - may optionally have these construct names.

They are useful both for identification (for clarity with nested or long constructs) but also for control under the exit statement (except to escape critical or do concurrent blocks).

The construct name may appear on the closing statement of the block, as in the question's example, but it is optional and must match if present.

francescalus
  • 30,576
  • 16
  • 61
  • 96
  • Great, thanks! Apparently they are also useful for advanced loop control as shown [here](https://stackoverflow.com/questions/19028669/how-to-use-fortran-statement-labels-well) – mivkov Jan 26 '18 at 18:32
  • Yes, that's the closest I found for what I assumed must exist as a duplicate target. In loops, where the `cycle` is useful, it is where we see labels most. – francescalus Jan 26 '18 at 18:34