VDM-10 Language Manual
VDM-10 Language Manual
VDM-10 Language Manual
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 />
elseif statement = ‘elseif’, expression, ‘then’, statement ;<br />
cases statement = ‘cases’, expression, ‘:’,<br />
cases statement alternatives,<br />
[ ‘,’, others statement ], ‘end’ ;<br />
cases statement alternatives =<br />
cases statement alternative,<br />
{ ‘,’, cases statement alternative } ;<br />
cases statement alternative = pattern list, ‘->’, statement ;<br />
others statement = ‘others’, ‘->’, statement ;<br />
Semantics: The semantics of the if statement corresponds to the if expression described in section<br />
6.4 except for the alternatives which are statements (and that the else part is optional) 3 .<br />
The semantics for the cases statement corresponds to the cases expression described in section<br />
6.4 except for the alternatives which are statements.<br />
Examples: Assuming functions clear winner and winner by more wins and operation<br />
RandomElement with the following signatures:<br />
✞<br />
✡✝<br />
clear_winner : set of Score -> bool<br />
winner_by_more_wins : set of Score -> bool<br />
RandomElement : set of Team ==> Team<br />
then the operation GroupWinner if demonstrates the use of a nested if statement (the<br />
iota expression is presented on page 50):<br />
✞<br />
GroupWinner_if : GroupName ==> Team<br />
GroupWinner_if (gp) ==<br />
if clear_winner(gps(gp))<br />
-- return unique score in gps(gp) which has more points<br />
-- than any other score<br />
then return ((iota sc in set gps(gp) &<br />
forall sc’ in set gps(gp) \ {sc} &<br />
sc.points > sc’.points).team)<br />
elseif winner_by_more_wins(gps(gp))<br />
-- return unique score in gps(gp) with maximal points<br />
-- & has won more than other scores with maximal points<br />
then return ((iota sc in set gps(gp) &<br />
forall sc’ in set gps(gp) \ {sc} &<br />
3 If the else part is omitted semantically it is like using else skip.<br />
✆<br />
<strong>10</strong>5