Quick Test 8: if ... then ... else



 
 

1. Which is not a valid comparison in PASCAL:

(a == b)
(a <> b)
(a = b)
(a > b)

2. The proper syntax for simple branching is

if condition 
     instruction;
case condition
     instruction;
if condition then 
     instruction;
case condition of
     instruction;


 

3. What is displayed when the following program is executed?

PROGRAM IfThenElse;

Var a, b, c, d: integer;

begin
  a := 5; b:= 3; c := 99; d := 5;
  if a>6 then Write('A');
  if a>b then Write('B');
  if b=c then
    begin
      Write('C');
      Write('D');
    end;
  if b<>c then Write('E') else Write('F');
  if a>=c then Write('G') else Write('H');
  if a<=d then
    begin
      Write('I');
      Write('J');
    end;
end.


 

4. To declare a constant called PI with a value of 3.1415927

Constant PI = 3.1415927;
Const PI = 3.1415927;
Const PI 3.1415927;
Constant PI 3.1415927