Conditional structures/ALGOL 68: Difference between revisions

Content added Content deleted
m (Minor improvements)
 
Line 126: Line 126:
PROC do_something = INT: random;
PROC do_something = INT: random;
PROC do_something_else = INT: random;
PROC do_something_else = INT: random;
input := (TRUE | do_something | do_something_else); # only calls do_something_else() #
input := (TRUE | do_something | do_something_else); # only calls do_something() #
)</lang>
)</lang>
The "( ~ | ~ | ~ )" is directly interchangeable with the "IF ~ THEN ~ ELSE ~ FI" syntax. Hence the above could be written:
The "( ~ | ~ | ~ )" is directly interchangeable with the "IF ~ THEN ~ ELSE ~ FI" syntax. Hence the above could be written:
Line 136: Line 136:
PROC do_something = INT: random;
PROC do_something = INT: random;
PROC do_something_else = INT: random;
PROC do_something_else = INT: random;
input := IF TRUE THEN do_something ELSE do_something_else FI; # only calls do_something_else() #
input := IF TRUE THEN do_something ELSE do_something_else FI; # only calls do_something() #
)</lang>
)</lang>
A more complex example created by combining the above:
A more complex example created by combining the above:
Line 143: Line 143:
CASE 2 IN x,y OUT z ESAC := IF 1+2=2 THEN 333 ELSE 666 FI
CASE 2 IN x,y OUT z ESAC := IF 1+2=2 THEN 333 ELSE 666 FI
)</lang>
)</lang>
In the result y becomes half-evil, with x and z remaining undefined.
In the result y becomes fully-evil, with x and z remaining undefined.