pascal if

Pascal if Statement

In Pascal, the if statement is used for conditional execution of code based on a Boolean expression. Here is the syntax for the if statement in Pascal:

if condition then
  // code to be executed if the condition is true
else
  // code to be executed if the condition is false

The condition is a Boolean expression that evaluates to either true or false. If the condition is true, the code block following the then keyword is executed. If the condition is false, the code block following the else keyword (if present) is executed.

Here's an example of using the if statement in Pascal:

var
  x: Integer;

begin
  x := 10;

  if x > 0 then
    writeln('x is positive')
  else if x < 0 then
    writeln('x is negative')
  else
    writeln('x is zero');
end.

In this example, the program checks the value of the variable x and prints a message based on its value. If x is greater than 0, it prints "x is positive". If x is less than 0, it prints "x is negative". Otherwise, if x is equal to 0, it prints "x is zero".

Please note that the code provided is for illustrative purposes and may not compile or run correctly in a Pascal compiler.