B side: Making choices and repeating

B B side · Fortran · The language that speaks maths
How do you say "if" and "again"?
13 Fortran words in this segment
13 Assembly words for the same job
What Fortran says well here
- Choices and loops are blocks: IF ... END IF, SELECT CASE, DO ... END DO. The shape of the text shows the logic.
What is hard to say
- You do not see the separate steps that the processor does.
One sentence in Fortran
if (fuel == 0) then call no_fuel()end ifIt says: If fuel is 0, run the subroutine no_fuel.
The words, by part of speech
Verbs (8) · A statement that does something, for example PRINT, CALL or ALLOCATE.
| Word | Meaning | Example |
|---|---|---|
| IF ... THEN ... END IF | Do a block only if a condition is true. | if (fuel <= 0.0) then |
| SELECT CASE | Choose one block from many, by the value of one name. | select case (key) |
| DO | Do a block again, a number of times. | do i = 1, 10 |
| DO WHILE | Do a block again while a condition is true. | do while (.not. landed) |
| EXIT | Stop the loop now. | exit |
| CYCLE | Go to the next turn of the loop. | cycle |
| STOP | Stop the program. | stop |
| ERROR STOP | Stop the program and report a failure. The build script sees the failure and stops. This is how a check says no. | if (mismatches /= 0) error stop 'The A side and the B side disagree.' |
Idioms (2) · A built-in function or subroutine, for example SQRT or MATMUL.
| Word | Meaning | Example |
|---|---|---|
| BTEST | Is one bit of a whole number 1? The same question as TEST on the A side. | if (btest(flags, 3)) then |
| MERGE | Choose the first value when the condition is true, or the second when it is false. One idiom replaces an IF block. | merge('true ', 'false', ok) |
Grammar marks (3) · Maths signs (+ - * / **), the = sign, and (:) for part of an array.
| Word | Meaning | Example |
|---|---|---|
| ELSE | Starts the block to do when the condition is false. | else |
| == /= < > <= >= | Compare two values: equal, not equal, less, greater, less or equal, greater or equal. | if (x /= 0) then |
| .and. .or. .not. | Join or reverse conditions. | if (a .and. .not. b) then |
Watch out: what the review found
These notes come from the review of the AI-written guides. They show traps that are easy to miss.
- D02-M7 major On real PCs, DRAM refresh, ISA wait states, the 8088 prefetch queue and 486 caches make exact cycle counts not practical. The claim is true on the C64 and NES. It is not true on the DOS target that the roadmap uses.