Something went wrong. Try again.
Actually just three programming languages in a trenchcoat
Something went wrong. Try again.
1.3 kB 38 lines
123456789101112131415161718192021222324252627282930313233343536373839\subsubsection{While}
The \kw{while} loop accepts a Boolean condition and repeats a block of codeuntil that condition evaluates to \kw{false}. \Trilogy{}'s \kw{while} loop isvery standard, as far as such loops go. There is no \texttt{do}\dots\texttt{while}loop in \Trilogy{}.
\begin{bnf*} \bnfprod{While}{ \bnfts{\kw{while}} \bnfsp \bnfpn{Expression} \bnfsp \bnfpn{Block} }\end{bnf*}
Branching may occur in the body of a \kw{while} loop, leading to more iterationsthan expected if not careful. However, since the \kw{while} loop provides no collectionmechanism, once those branches break out of the loop they will continue to executebeyond the end of the loop.
If the expression in the condition of the \kw{while} loop does not evaluate to aBoolean, it is a runtime type error.
\begin{prooftree} \AxiomC{$\Gamma\vdash C = \kw{true}$} \AxiomC{$\Gamma\vdash B \Rightarrow \Phi$} \AxiomC{$\Phi\vdash \kw{while}\ C\ B \Rightarrow\Sigma$} \LeftLabel{Loop} \TrinaryInfC{$\Gamma\vdash \kw{while}\ C\ B \Rightarrow \Sigma$}\end{prooftree}
\begin{prooftree} \AxiomC{$\Gamma\vdash C = \kw{false}$} \LeftLabel{End Loop} \UnaryInfC{$\Gamma\vdash \kw{while}\ C\ B:\top$}\end{prooftree}