Control Structures
Steve Lantz, Adam Brazier (revisions)
Cornell Center for Advanced Computing
Revisions: 2/2023, 10/2014, 6/2012 (original)
Like any programming language, Fortran necessarily includes syntax for branching and looping. Here we show you how to create the basic types of control structures: if-then-else, as well as loops governed by a counter, a condition, or a combination of both.
Objectives
After you complete this topic, you should be able to:
- Identify essential control constructs in Fortran
- Write an
if
condition followed bythen
andelse
clauses - Show how
else if
is used to insert additional clauses - Explain where to use a
do
loop and awhile
loop - Show how to break out of a loop conditionally
- Create any type of branch or loop structure
Prerequisites
- Familiarity with an editor
- Knowledge of how to execute simple commands on the command line
- Some basic understanding of what a computer language is