01 — the DO loop
FORTRAN’s original workhorse: iterate I from 1 to N, the compiler turns it into tight machine code.
SUM = 0.0
DO I = 1, N
SUM = SUM + A(I)
END DO§ 02 — Eras · 1957
the oldest language still in production — built for speed
Left: era context, features, and the 101 hello. Right: 3 core concepts, 4 deeper 201 lessons, the factorial specimen, and where FORTRAN lives today — each column scrolls on its own.
Programmers cost more than machines. FORTRAN let scientists write mathematics and get machine-speed code back from a compiler.
Punch-card ceremony: fixed columns, six-character names, and dialects that fragmented for decades afterward.
Session one is the smallest program that still counts as speaking FORTRAN: what every tutorial prints first, in the dialect that mattered when the language arrived (1957).
print *, "Hello, world"101First contact — hello world and 3 ideas that define how FORTRAN reads. 201 — 4 lessons on mechanisms you meet after the factorial specimen: the sharp edges practitioners actually use.
3 fragments, each naming a habit of mind in FORTRAN. Read the note, then the code — together they are the 101 in one sitting.
01 — the DO loop
FORTRAN’s original workhorse: iterate I from 1 to N, the compiler turns it into tight machine code.
SUM = 0.0
DO I = 1, N
SUM = SUM + A(I)
END DO02 — column-agnostic arrays
Arrays are the native data type — one-indexed by default, contiguous in memory, and blindingly fast.
REAL :: A(10, 10)
A(1, 1) = 3.14
PRINT *, SIZE(A)03 — functions & subroutines
Subprograms with explicit interfaces — the ancestor of every function signature since.
FUNCTION AVG(X, N) RESULT(R)
REAL :: X(N), R
R = SUM(X) / N
END FUNCTIONThe 201 assumes you have read the 101 and the specimen. Each lesson is one mechanism — what it is for, how it looks in code, and the trap or payoff that makes FORTRAN distinctive at scale.
Modern Fortran requires the interface of a procedure to be visible at the call site — a direct descendant of the original insistence on typed, checkable calls.
module Geometry
implicit none
contains
function area(r) result(a)
real :: r, a
a = 3.14159265 * r ** 2
end function
end moduleUser-defined types bundle related data and can carry procedures — the nearest thing FORTRAN has to objects, and a late addition for compatibility.
type :: Ship
character(len=20) :: name
real :: tons
end type Ship
type(Ship) :: s
s%name = "Perch"Any part of an array can be addressed as a whole, and assignment operates on all of it at once — vectorization without writing a loop.
a(1:10) = b(1:10) * 2.0 ! whole slices
where (a > 0) a = 1.0/a ! masked assignmentColumn-major storage means the first index varies fastest — the opposite of C. Getting the loop order wrong can cost two orders of magnitude.
! slow: j varies fastest
do j = 1, n
do i = 1, m
a(i,j) = b(i,j) + c(i,j)
end do
end doThe DO loop, compiled: FORTRAN’s optimizer proved high-level code could match hand-written assembly — and the punch card’s fixed columns set programming’s ceremony for a decade.
SUM = 0.0
DO 10 I = 1, N
10 SUM = SUM + A(I)installbrew install gfortran
rungfortran fact.f -o fact && ./fact
The world’s top supercomputers still rank each other with LINPACK benchmarks written in FORTRAN; every weather forecast you have ever received passed through it.