Your first program

Contents
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

Related articles
Fortran
Fortran course: zero to hero in 50 lessons
What is Fortran and where it runs
Install gfortran
Your first program
Program structure
Types: integer real complex logical character
Kind parameters
Operators
Conditions
DO loops
Arrays
Array sections
Character strings
Formatted IO
Files
Subroutines and functions
Modules
USE with ONLY
INTENT
OPTIONAL and PRESENT
Explicit interfaces
Derived types
Type-bound procedures
Object orientation
Operator overloading
Finalization
Allocatable arrays
Pointers in Fortran
DO CONCURRENT
Coarrays
OpenMP basics
Namelists
IEEE arithmetic
Intrinsic matrix math
Random numbers
String tools
Command-line arguments
Environment variables
error stop
Testing
Build with gfortran and make
Debugging
C interoperability
From fixed form to free form
Numeric models
Performance
Modern Fortran tour: 2008, 2018, 2023
Capstone: stats tool
Capstone: 1D heat equation
Style guide
Hero roadmap: the whole course on one page
Install gfortran on Windows 11
Install gfortran on Ubuntu
Install gfortran on Rocky Linux
Install gfortran on macOS
Install gfortran on FreeBSD
Fortran in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: