typestar

Declarations in Fortran

Four typed variables for the lighthouse log, declared before any statement runs.

program declarations
    ! implicit none turns off the 1950s i-through-n typing rules.
    implicit none
    integer :: lamp_turns = 148
    real :: oil_gallons = 6.5
    character(len=12) :: station = "Gull Rock"
    logical :: storm_watch = .true.

    print *, "Station: ", station
    print *, "Turns tonight: ", lamp_turns
    print *, "Oil on hand: ", oil_gallons
    print *, "Storm watch? ", storm_watch
end program declarations

How it works

  1. implicit none turns off the 1950s rule that typed variables by their first letter.
  2. integer, real, character(len=12), and logical cover the basics; :: splits type from name.
  3. Initializers ride on the declaration, and .true. is how logicals are spelled.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
396
Tokens
59
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 51 seconds.

Type this snippet

Step 2 of 3 in Programs & variables, step 2 of 27 in Language basics.

← Previous Next →

Declarations in other languages