Senin, Agustus 27, 2018

Make Set On Pascal Programming

Processing...

For example we have set of integer with member: (2,3,4,5,6,7,8), that can be written on pascal programming as follows:
var
a:set of 2..8;

begin
a:=[3,4,5,6];
end.
Or
var
a:set of 2..8;

begin
a:=[3..6];
end.

If we want to show the member, then syntax of our program will become:
var
a:set of 2..8;
a1:integer;

begin
a:=[3..6];
for a1 in a do
begin
writeln(a1);
end;
readln;
end.
If program beside is run, then will shown:
3
4
5
6
a: set of 2..8 variable means, on body of program can be defined a set with member include in range 2≤a≤5. On body of program, a set is defined has member [2,3,4,5] or [3..6]. The four member of the set will be defined cause they are include in range 2≤a≤5.

But if on body of program, we define a set has member [1..4] so that syntax of our program be as follows:
var
a:set of 2..8;
a1:integer;

begin
a:=[1..4];
for a1 in a do
begin
writeln(a1);
end;
readln;
end.
If the program beside is run, then will shown:
2
3
4
1 member will not shown when program is run, because 1 is not defined caused is not include in range 2≤a≤8.

a1 variable is variable show one value of member of set is defined on body of program which a1 value always change alternately corresponding to member of set is defined on body of program as long as include in range of set is defined on variable segment

Happened iteration on section of syntax:
...
for a1 in a do
begin
writeln(a1);
end;
...
Part is located between begin and end is repeated part.

Example, we add n variable to know number of iteration:
var
a:set of 2..8;
a1,n:integer;

begin
a:=[1..4];
for a1 in a do
begin
writeln(a1);
n:=n+1;
writeln('This is iteration-',n);
writeln
end;
readln;
end.
If program beside is run, then will be shown:
2
This is iteration-1

3
This is iteration-2

4
This is iteration-3

0 komentar: