class Store
public:
/* public section. Only methods are allowed */
// method get returning an integer
proc
get() : integer
begin
// n is the method return value
return n;
end
proc
put( pn : integer )
begin
n = pn;
end
private:
// declares an instance variable n
var
n : integer;
end
An object is allocated with new :
s
= Store.new();
s.put(5);
Command if has the form
if
exp
then
commands
else
commands
endif
in which the else part is optional. The endif keyword makes it impossible to associate the else with the wrong if in nested if commands.
There are commands for while, repeat-until, loop-end (endless loop finished by break), and for. These will not be discussed here although you can see some examples:
for i = 1 to n do
Out.writeln(i);
i = 1;
while i <= n do
begin
Out.writeln(i);
++i;
end
i = 1; // considers n >= 1
repeat
Out.writeln(i);
++i;
until i > n;
i = 1;
loop
if i > n then break; endif
Out.writeln(i);
++i;
end