Commit 706dc14d authored by Richard Xiong's avatar Richard Xiong
Browse files

Filled in Gap 4

parent 6975b778
No preview for this file type
......@@ -412,7 +412,15 @@ 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{while} is used to loop 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{bool}, and a \lit{do} body statement to be executed if the condition is satisfied.
If the condition evaluates to \lit{true}, then the body statement is executed, until the \lit{done} keyword is reached. The \lit{while} 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{true}.
Otherwise, the program exits out of the loop, and continues to execute the next statement. If initially the condition evaluates to \lit{false}, the body statement
is never executed.
The condition statement may also never evaluate to \lit{true}. In this case, the loop is an infinite loop, 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