NASutils Knowledge BaseUnofficialPolski

Pascal · lesson 8 of 30 · Decisions and loopsJoin conditions

and, or and xor join Boolean values, not turns one round. Put each comparison in brackets.

Programming on the NAS › Pascal in 30 lessons

08-conditions.pas Download 08-conditions.pas

program Conditions;
var
  Free: Integer;
  BackupOk: Boolean;
begin
  Free := 12;
  BackupOk := True;
  WriteLn('low: ', Free < 20);
  WriteLn('low and no backup: ', (Free < 20) and not BackupOk);
  WriteLn('low or no backup: ', (Free < 20) or not BackupOk);
  WriteLn('exactly one: ', (Free < 20) xor BackupOk);
  WriteLn('between 10 and 20: ', (Free >= 10) and (Free <= 20));
end.

Terminal

$ ./08-conditions
low: TRUE
low and no backup: FALSE
low or no backup: TRUE
exactly one: FALSE
between 10 and 20: TRUE

Exercise

Print True only for a leap year.