25.07.2014 Views

VDM-10 Language Manual

VDM-10 Language Manual

VDM-10 Language Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13. Statements<br />

13.7 The While-Loop Statement<br />

Syntax: statement = . . .<br />

| while loop<br />

| . . . ;<br />

while loop = ‘while’, expression, ‘do’, statement ;<br />

Semantics: The semantics for the while statement corresponds to the while statement from traditional<br />

programming languages. The form of a while loop is:<br />

✞<br />

✡✝<br />

while e do<br />

s<br />

where e is a boolean expression and s a statement. As long as the expression e evaluates to<br />

true the body statement s is evaluated.<br />

Examples: The while loop can be illustrated by the following example which uses Newton’s<br />

method to approximate the square root of a real number r within relative error e.<br />

✞<br />

✡✝<br />

SquareRoot : real * real ==> real<br />

SquareRoot (r,e) ==<br />

(dcl x:real := 1,<br />

nextx: real := r;<br />

while abs (x - nextx) >= e * x do<br />

( x := nextx;<br />

nextx := ((r / x) + x) / 2;<br />

);<br />

return nextx<br />

);<br />

✆<br />

✆<br />

13.8 The Nondeterministic Statement<br />

Syntax: statement = . . .<br />

| nondeterministic statement<br />

| . . . ;<br />

nondeterministic statement =<br />

‘||’, ‘(’, statement,<br />

{ ‘,’, statement }, ‘)’ ;<br />

Semantics: The nondeterministic statement has the form:<br />

<strong>10</strong>9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!