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

Fortran Cheat Sheet

Fortran Cheat Sheet

Core modern Fortran syntax covering variable declarations, control flow, arrays, and procedures for scientific and numerical computing.

2 PagesIntermediateMar 30, 2026

Program Structure & Variables

Basic program layout and variable declarations.

fortran
program hello    implicit none          ! always use this    integer :: i, j    real :: x, y    real(kind=8) :: z      ! double precision    character(len=20) :: name    logical :: flag    x = 3.14    name = 'Fortran'    print *, 'Hello, World!'    print *, 'x =', xend program hello

Control Flow

If blocks, select case, and loops.

fortran
if (x > 0) then    print *, 'positive'else if (x < 0) then    print *, 'negative'else    print *, 'zero'end ifselect case (n)case (1)    print *, 'one'case (2:5)    print *, 'two to five'case default    print *, 'other'end selectdo i = 1, 10    print *, iend dodo while (x < 10.0)    x = x + 1.0end do

Arrays

Array declarations, slicing, and array intrinsics.

fortran
integer :: arr(10)integer, dimension(3,3) :: matrixreal, allocatable :: dyn(:)arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]arr(1:5) = 0             ! slice assignmentallocate(dyn(100))print *, sum(arr)        ! sum of all elementsprint *, size(arr)       ! number of elementsprint *, maxval(arr)     ! largest elementdeallocate(dyn)

Subroutines, Functions & Modules

Defining reusable procedures and organizing code into modules.

fortran
module mymod    implicit nonecontains    function square(x) result(y)        real, intent(in) :: x        real :: y        y = x * x    end function square    subroutine greet(name)        character(len=*), intent(in) :: name        print *, 'Hello, ', name    end subroutine greetend module mymodprogram main    use mymod    implicit none    call greet('World')    print *, square(4.0)end program main
Pro Tip

Always start every program unit with `implicit none` — it forces you to declare every variable and catches typos that would otherwise silently create new real variables at compile time.

Was this cheat sheet helpful?

Explore Topics

#Fortran#FortranCheatSheet#Programming#Intermediate#ProgramStructureVariables#ControlFlow#Arrays#SubroutinesFunctionsModules#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet