18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix A 367<br />

if Temp < 15 then Put("Cool"); end if;<br />

if Temp < 15 then Put("Cool"); else Put("Warm"); end if;<br />

case Number is<br />

when 2+3 => Put("Is 5");<br />

when 7 => Put("Is 7");<br />

when others => Put("Not 5 or 7");<br />

end case;<br />

Loop<strong>in</strong>g statements<br />

while Ra<strong>in</strong><strong>in</strong>g loop --While ra<strong>in</strong><strong>in</strong>g<br />

Work; -- Perform work<br />

end loop; --<br />

loop --Repeat<br />

Work; -- Perform work<br />

exit when Sunny; -- exit from loop when sunny<br />

end loop; --<br />

for I <strong>in</strong> 1 .. 10 loop --Vary I from 1 to 10<br />

Put(I); New_L<strong>in</strong>e; -- Write I<br />

end loop; --<br />

Arithmetic operators<br />

Res := A + B; --plus<br />

Res := A - B; --m<strong>in</strong>us<br />

Res := A * B; --multiplication<br />

Res := A / B; --Division<br />

Res := A mod B; --Modulus<br />

Res := A rem B; --Rema<strong>in</strong>der<br />

Conditional expressions<br />

if A = B then --Equal to<br />

if A > B then --Greater than<br />

if A < B then --Less than<br />

if A /= B then --Not equal<br />

if A >= B then --Greater<br />

-- or equal<br />

if A 15 and Dry then<br />

Note:<br />

When us<strong>in</strong>g and then or or else the conditional expression will only be evaluated as far as<br />

necessary to produce the result of the condition. Thus <strong>in</strong> the if statement:<br />

if fun_one or else fun_two then<br />

fun_two will not be called if fun_one delivered true.<br />

Exits from loops<br />

© M A Smith - May not be reproduced without permission

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

Saved successfully!

Ooh no, something went wrong!