Icon+Unicon/Intro: Difference between revisions

Content added Content deleted
Line 700: Line 700:
write("Surprise!") # this time this IS executed, and the procedure fails when it runs into the 'end' statement
write("Surprise!") # this time this IS executed, and the procedure fails when it runs into the 'end' statement
end</lang>
end</lang>
Just for completeness:
<lang Icon>...
fail &fail # is a syntax error
</lang>
As one can see this is less about the behavior of &fail as it is about the behavior of return and suspend.
As one can see this is less about the behavior of &fail as it is about the behavior of return and suspend.

'&fail' does have uses as can be seen in this example from [https://www.cs.arizona.edu/icon/progcorn/pc_inl21.htm|The Icon Programming Corner]:
<lang Icon>
# The outcome of a looping expression such as

while expr1 do expr2

# need not be failure. If a break expression in either expr1 or expr2 is evaluated,
# the outcome of the looping expression is the outcome of the argument of the break expression.

# It is common to omit the argument of a break expression. In this case, the argument defaults to a null value.
# Consequently, if the break expression in

while expr1 do {
. . .
break
. . .
}

# is evaluated, the outcome of the looping expression is the null value.
# In fact, if this effect is not wanted,

break &fail

# can be used to assure the outcome of the looping expression is failure.

# However, the argument of a break expression can be a generator. For example, if break 1 to 5
# is evaluated in a looping expression, the result sequence for the looping expression is {1, 2, 3, 4, 5}.
</lang>


=== Semi-colons ===
=== Semi-colons ===