pascal if else

In Pascal, the "if" statement is used to perform conditional execution of code. It allows you to specify a condition and execute a block of code if the condition is true. The "else" statement can be used to specify an alternative block of code to execute if the condition is false.

Here is the basic syntax for the "if" statement in Pascal:

if condition then
  begin
    // code to execute if the condition is true
  end
else
  begin
    // code to execute if the condition is false
  end;

The "condition" is a Boolean expression that evaluates to either true or false. If the condition is true, the code inside the "begin" and "end" block after the "if" statement is executed. If the condition is false, the code inside the "begin" and "end" block after the "else" statement is executed.

Here's an example that illustrates the usage of the "if" and "else" statements in Pascal:

program IfElseExample;

var
  number: Integer;

begin
  writeln('Enter a number: ');
  readln(number);

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

  readln;
end.

In this example, the program prompts the user to enter a number. Depending on the value of the number, it prints out a corresponding message. If the number is greater than 0, it prints "The number is positive." If the number is less than 0, it prints "The number is negative." Otherwise, if the number is equal to 0, it prints "The number is zero."

This is a basic example of how to use the "if" and "else" statements in Pascal. You can also use additional "if" and "else" statements inside the blocks to create more complex conditional logic.