Every Fortran source has a program unit. implicit none disables Fortran's legacy implicit typing, so every name must be declared.

Program

Play the program to watch a character name flow into a greeting and print.

hello.f90
Replay: real traced execution (multi-file project)
program hello
    implicit none
    character(len=20) :: name
    name = "Ada"
    print '(A)', "Hello, " // trim(name) // "!"
end program hello
  1. name ← Ada

    3character(len=20) :: name4name = "Ada"5print '(A)', "Hello, " // trim(name) // "!"
    values this stepAdaname
  2. print '(A)', "Hello, " // trim(name) // "!"

    4    name = "Ada"5    print '(A)', "Hello, " // trim(name) // "!"6end program hello
    outputHello, Ada!
    values this stepAdaname

Follow the Greeting

  1. The program declares name as a character value with room for 20 characters.
  2. name = "Ada" stores the text Ada.
  3. trim(name) removes the unused blank space after Ada.
  4. The pieces join into Hello, Ada!.
  5. print writes that greeting. | piece | value | | --- | --- | | name | Ada | | trim(name) | Ada | | printed text | Hello, Ada! |
program `program ... end program` wraps the main entry point.
implicit none `implicit none` forces every variable to be explicitly declared.
// and trim `//` concatenates strings; `trim` removes trailing blanks.

Exercise: hello.f90

Reproduce the printed greeting Hello, Ada!, then change the name and predict the exact greeting before running it.