if and end if in Fortran
A sailing call in an if chain: then blocks, else if rungs, end if closing.
program if_else
implicit none
integer :: wind_knots = 26
! Blocks close with end if; else if chains in between.
if (wind_knots > 33) then
print *, "Gale: stay in harbor"
else if (wind_knots > 21) then
print *, "Reef the main and go"
else
print *, "Fair wind, full sail"
end if
end program if_else
How it works
if (wind_knots > 33) thenopens the gale branch.else if (...) thenchains the reefing decision without nesting.- The whole construct closes with a single
end if.
Keywords and builtins used here
elseendifimplicitintegernoneprintprogramthen
The run, in numbers
- Lines
- 13
- Characters to type
- 297
- Tokens
- 43
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 34 seconds.
Step 1 of 3 in Control flow, step 7 of 27 in Language basics.