select case in Fortran
Depth bands routed by select case: open ranges, closed ranges, and a default.
program select_case
implicit none
integer :: depth_m = 42
! select case takes values and ranges; default catches the rest.
select case (depth_m)
case (:10)
print *, "Snorkel water"
case (11:40)
print *, "Open-water dive"
case (41:60)
print *, "Deep dive: plan your stops"
case default
print *, "Submersible territory"
end select
end program select_case
How it works
select case (depth_m)names the subject once.case (:10)is everything up to 10;case (11:40)is a closed band.case defaultcatches what no band claimed, andend selectcloses.
Keywords and builtins used here
caseendimplicitintegernoneprintprogramselect
The run, in numbers
- Lines
- 16
- Characters to type
- 353
- Tokens
- 55
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 47 seconds.
Step 2 of 3 in Control flow, step 8 of 27 in Language basics.