100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Your First Fortran Program

A hands-on walkthrough of writing, compiling, and running a simple Fortran program, from source file to executable.

FoundationsBeginner8 min readJul 10, 2026
Analogies

Your First Fortran Program

Writing your first Fortran program means creating a plain text file with a .f90 extension, since modern free-form Fortran source files conventionally use this suffix, and typing a small, complete program unit into it. A minimal but real program declares implicit none, defines any variables it needs, prints something with the print statement, and closes with end program. Unlike some languages, Fortran does not require a semicolon at the end of each line, since a newline itself terminates a statement.

🏏

Cricket analogy: Like a young batsman's very first net session focusing only on getting bat on ball, your first Fortran program focuses only on the basics: declare, print, end.

Compiling and Running the Program

Once hello.f90 is saved, compiling it is a single terminal command: gfortran hello.f90 -o hello, which produces an executable file named hello (or hello.exe on Windows). Running it is then done from the same terminal with ./hello on macOS/Linux or hello.exe on Windows. If the compiler reports errors, it will point to the specific line and column number, and the most frequent beginner mistakes are missing implicit none, forgetting to declare a variable, or mismatched parentheses in a print or format statement.

🏏

Cricket analogy: Like a bowler's action being checked by a biomechanist for legality before a match, gfortran hello.f90 -o hello checks your code for compile errors before producing something you can actually run.

Reading Compiler Error Messages

When gfortran finds a problem, it prints the file name, line number, and a caret pointing at the exact column, followed by an error description such as Error: Symbol 'x' at (1) has no IMPLICIT type. Learning to read this output methodically, starting from the very first error reported, since later errors are often just consequences of the first, is one of the fastest ways to become productive in Fortran, or in fact any compiled language.

🏏

Cricket analogy: Like a third umpire's replay showing the exact frame where the ball clips the bail, gfortran's caret points to the exact column where the error occurs.

Always fix the first error reported by the compiler first, then recompile. Later errors in the same run are frequently just cascading consequences of the first mistake, such as a missing declaration confusing everything that follows it.

fortran
program first_program
    implicit none
    integer :: apples
    integer :: oranges
    integer :: total

    apples = 3
    oranges = 5
    total = apples + oranges

    print *, "Total fruit:", total
end program first_program
  • Modern free-form Fortran source files conventionally use the .f90 extension.
  • A minimal program has implicit none, variable declarations, executable statements, and end program.
  • Compile with gfortran file.f90 -o output_name, then run with ./output_name (or output_name.exe on Windows).
  • Fortran statements are terminated by a newline, not a semicolon.
  • Compiler errors report the exact file, line, and column, followed by a description of the problem.
  • Always fix the first reported error first, since later errors are often caused by it.
  • Common beginner mistakes include missing implicit none, undeclared variables, and mismatched parentheses.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#FortranStudyNotes#YourFirstFortranProgram#Fortran#Program#Compiling#Running#StudyNotes#SkillVeris#ExamPrep