Skip to content
Loops and Conditionals
step 1/5

Reading — step 1 of 5

Learn

~1 min readArrays and Loops

do loops:

do i = 1, 10
    print *, i
end do

do i = 10, 1, -1            ! step
    print *, i
end do

do while (n < 100)
    n = n * 2
end do

if/else if/else:

if (x > 0) then
    print *, "positive"
else if (x < 0) then
    print *, "negative"
else
    print *, "zero"
end if

Comparison operators: ==, /=, <, >, <=, >=. Old Fortran style .eq. .ne. .lt. .gt. .le. .ge. still works — older code uses these.

Logical operators: .and., .or., .not. (with the dots).

select case (switch):

select case (grade)
    case ("A")
        print *, "excellent"
    case ("B":"D")        ! range
        print *, "passing"
    case default
        print *, "failed"
end select

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…