typestar

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

  1. if (wind_knots > 33) then opens the gale branch.
  2. else if (...) then chains the reefing decision without nesting.
  3. The whole construct closes with a single end if.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 3 in Control flow, step 7 of 27 in Language basics.

← Previous Next →