Commit 6face9eb authored by Luke  Thorpe's avatar Luke Thorpe
Browse files

Improved answer to 'Gap 4'

parent 0edb94a3
No preview for this file type
......@@ -418,15 +418,12 @@ Otherwise, the \lit{else} body statement is executed.
Each of the program branches is executed in its own scope, which are denoted by the \lit{then} and \lit{else} tokens and the \lit{else} and \lit{fi} tokens, respectively.
\paragraph{While Loop Statements:}
\hl{A while loop statement} \lit{\hl{while}} \hl{is used to loop over a body statement, depending on the truth value of the condition given.
\hl{A while loop statement} \lit{\hl{while}} \hl{is used to iterate over a body statement, depending on the truth value of the condition given.
The statement is given a condition expression, that must be of type} \lit{\hl{bool}}\hl{, and a} \lit{\hl{do}} \hl{body statement to be executed if the condition is satisfied.}
\hl{If the condition evaluates to }\lit{\hl{true}}\hl{, then the body statement is executed, until the} \lit{\hl{done}} \hl{keyword is reached. The} \lit{\hl{while}} \hl{loop then re-evaluates the condition again, using the
updated program state after executing the body statement, and the body statement is executed repeatedly as long as the condition evaluates to }\lit{\hl{true}}\hl{.
Otherwise, the program exits out of the loop, and continues to execute the next statement. If initially the condition evaluates to }\lit{\hl{false}}\hl{, the body statement
is never executed.
\hl{If the condition evaluates to }\lit{\hl{true}}\hl{, then the body statement is executed, until the} \lit{\hl{done}} \hl{keyword is reached. The} \lit{\hl{while}} \hl{loop then re-evaluates the condition again, using the updated program state after executing the body statement, and the body statement is executed repeatedly as long as the condition evaluates to }\lit{\hl{true}}\hl{.Otherwise, the program exits out of the loop, and continues to execute the next statement.}
The condition statement may also never evaluate to} \lit{\hl{true}}\hl{. In this case, the loop is an infinite loop, and the program will never terminate.}
\hl{If initially the condition evaluates to }\lit{\hl{false}}\hl{, then the body statement is never executed. Conversely, the condition statement may never evaluate to} \lit{\hl{false}}\hl{; in this case, the loop will iterate indefinitely, and the program will never terminate.}
\fillgap{\hl{Define/describe while loop statements}}{6 marks}
\paragraph{Scoping Statements:}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment