1. Write a for loop to display the following output
1 2 3 4 5 6 7 8 9 10
2. Write a for loop to display the following output
1
22
333
4444
55555
3. Write a while loop to display the following output
A B C D E F
4. Rewrite the following if statements as a Case statement
if flag = 1 then number := 10
else if flag = 2 then number := 20
else if flag = 3 then number := 40;
5. Define an enumerated data type called chair, which has the set of values lounge, deck, executive
6. Write pascal statements to define a new working variable mychair, of type chair, and assign the value deck to this new variable.
7. Define a new subrange called minutes, which has a set of ranges from 0 to 60.
SELF TEST: ANSWERS
1. Write a for loop to display the following output
1 2 3 4 5 6 7 8 9 10for loop := 1 to 10 do write( loop, ' ' );
2. Write a for loop to display the following output
1
22
333
4444
55555
for loop := 1 to 5 do
begin
for loop1 := 1 to loop do write( loop );
writeln
end
3. Write a while loop to display the following output
A B C D E Floop := 'A';
while loop <= 'F' do
begin
write( loop, ' ' );
loop := loop + 1
end;
4. Rewrite the following if statements as a Case statement
if flag = 1 then number := 10
else if flag = 2 then number := 20
else if flag = 3 then number := 40;case flag of
1 : number := 10;
2 : number := 20;
3 : number := 40
end;
5. Define an enumerated data type called chair, which has the set of values lounge, deck, executive
type chair = ( lounge, deck, executive );
6. Write pascal statements to define a new working variable mychair, of type chair, and assign the value deck to this new variable.
var mychair : chair;mychair := deck;
7. Define a new subrange called minutes, which has a set of ranges from 0 to 60.
type minutes = 0..60;