short_circuit.adb
Table of Contents
with Text_IO, Ada.Integer_Text_IO;
use Text_IO, Ada.Integer_Text_IO;
 
procedure Short_Circuit is
 
function Is_Odd (i : Integer) return Boolean
is
begin
  Put ("Testing");
  Put (i);
  New_Line;
  return ((i / 2) * 2) /= i;
end;
 
begin
  Put_Line ("Testing if ""5 and 6"" are odd");
  if (Is_Odd (5) and Is_Odd (6)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""5 or 6"" are odd");
  if (Is_Odd (5) or Is_Odd (6)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""5 and then 6"" are odd");
  if (Is_Odd (5) and then Is_Odd (6)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""5 or else 6"" are odd");
  if (Is_Odd (5) or else Is_Odd (6)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""6 and 5"" are odd");
  if (Is_Odd (6) and Is_Odd (5)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""6 or 5"" are odd");
  if (Is_Odd (6) or Is_Odd (5)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""6 and then 5"" are odd");
  if (Is_Odd (6) and then Is_Odd (5)) then
    Put_Line ("True");
  else
    Put_Line ("False");
  end if;
 
  Put_Line ("Testing if ""6 or else 5"" are odd");
  if (Is_Odd (6) or else Is_Odd (5)) then
    Put_Line ("True");
  else
   Put_Line ("False");
  end if;
end Short_Circuit;

Podobne strony

Podobne StronySparkPlik Na EkranAckermannWartościowanie leniwe
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License