mivkov
mivkov

Reputation: 553

What is the colon before Fortran if `something:if(some_condition) then`?

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?

Upvotes: 3

Views: 275

Answers (1)

francescalus
francescalus

Reputation: 32366

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.

Upvotes: 5

Related Questions