- Fortran - Home
- Fortran - Overview
- Fortran - Environment Setup
- Fortran - Basic Syntax
- Fortran - Data Types
- Fortran - Variables
- Fortran - Constants
- Fortran - Operators
- Fortran - Decisions
- Fortran - Loops
- Fortran - Numbers
- Fortran - Characters
- Fortran - Strings
- Fortran - Arrays
- Fortran - Dynamic Arrays
- Fortran - Derived Data Types
- Fortran - Pointers
- Fortran - Basic Input Output
- Fortran - File Input Output
- Fortran - Procedures
- Fortran - Modules
- Fortran - Intrinsic Functions
- Fortran - Numeric Precision
- Fortran - Program Libraries
- Fortran - Programming Style
- Fortran - Debugging Program
Fortran - Exit Statement
Exit statement terminates the loop or select case statement, and transfers execution to the statement immediately following the loop or select.
Flow Diagram
Example
program nestedLoop
implicit none
integer:: i, j, k
iloop: do i = 1, 3
jloop: do j = 1, 3
kloop: do k = 1, 3
print*, "(i, j, k): ", i, j, k
if (k==2) then
exit jloop
end if
end do kloop
end do jloop
end do iloop
end program nestedLoop
When the above code is compiled and executed, it produces the following result −
(i, j, k): 1 1 1 (i, j, k): 1 1 2 (i, j, k): 2 1 1 (i, j, k): 2 1 2 (i, j, k): 3 1 1 (i, j, k): 3 1 2
fortran_loops.htm
Advertisements