MAKING DECISIONS
Most programs need to make decisions. There are several statements available in the Pascal language for this. The IF statement is one of the them. The RELATIONAL OPERATORS, listed below, allow the programmer to test various variables against other variables or values.

Symbol Meaning
= Equal to
> Greater than
< Less than
<> Not equal to
<= Less than or equal to
>= Greater than or equal to

 

The format for the IF THEN Pascal statement is,


	if  condition_is_true  then
		execute_this_program_statement;

The condition (ie, A < 5 ) is evaluated to see if it's true. When the condition is true, the program statement will be executed. If the condition is not true, then the program statement following the keyword then will be ignored.


	program IF_DEMO (input, output);  {Program demonstrating IF THEN statement}
	var     number, guess : integer;
	begin
	        number := 2;
	        writeln('Guess a number between 1 and 10');
	        readln( guess );
	        if number = guess then  writeln('You guessed correctly. Good on you!');
	        if number <> guess  then  writeln('Sorry, you guessed wrong.')
	end.


Copyright B Brown/P Henry, 1988-1999. All rights reserved.