Next: Logical Expressions
Up: Logical Expressions
Previous: Logical Expressions

Logical IF

It is sometimes the case that a block IF consists of exactly one statement, and contains no ``ELSE IF'' or ``ELSE'' clauses. In this case there is a shortcut that you can take. Take a look at ``logic1.f'' in your ``examples'' directory (or view it directly) for an example.

This program reads an integer and then prints out whether it is odd and whether it is even. In either case only one statement---a PRINT---is executed if the condition is true.

In the first case we have used a block IF, and in the second case we have used a logical IF. Notice that using the logical IF saves us from having to use ``THEN'' and ``ENDIF'' and makes the program a bit shorter and easier to read. But remember---this only works when you have exactly one statement to execute if the condition is true.

If you think that the difference between the two forms of IF is confusing, then just forget about logical IF. Anything that you can do with a logical IF, you can also do with a block IF. But the reverse is not true.


Next: Logical Expressions
Up: Logical Expressions
Previous: Logical Expressions

Hamlet Project
hamlet@cs.utah.edu