Your first program
| program unit | |
| print to screen | |
| Compile it | |
| Common beginner mistakes |
program unit
A standalone Fortran program starts with the program statement, contains declarations and actions, and ends with end program.
The second line, implicit none, turns off old automatic typing and forces every name to be declared. Always include it.
program hello
implicit none
print *, "Hello, Fortran"
end program hello
Save this text as hello.f90. The .f90 ending means free form source, which is the only style used in this course.
print to screen
The print statement with an asterisk writes to the screen with default formatting, which is perfect for learning.
Text goes in double quotes, numbers and variables follow the comma, and each print starts a new line.
program demo
implicit none
print *, "2 + 3 =", 2 + 3
end program demo
Compile it
Compile the saved file with gfortran and run the created binary.
gfortran -Wall -Wextra -std=f2018 hello.f90 -o hello
./hello
Hello, Fortran
Warning flags do not change the program. They only ask the compiler to report suspicious code before it builds the binary.
Common beginner mistakes
Most first errors come from three habits: a missing implicit none, a missing end program line, or single quotes around text.
Use double quotes for strings, close every program unit, and keep implicit none as the first line inside the unit.
When the compiler reports a line number, open the file at that exact line first. The cause is usually a missing comma or a misspelled name right above it.
program careful
implicit none
integer :: year
year = 2026
print *, "Year =", year
end program careful
Next: Program structure
Article author: Arthur Isaev