# Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:

## Presentation on theme: "Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:"— Presentation transcript:

Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include: –if statements –case statements

Pascal Programming Today Chapter 4 2 If-then-else Statements Syntax of if-then-else statements if then else May be a Boolean constant, Boolean variable or Boolean expression.

Pascal Programming Today Chapter 4 3 If-then-else Statements Syntax of if-then-else statements if then else Will be executed if is TRUE.

Pascal Programming Today Chapter 4 4 If-then-else Statements Syntax of if-then-else statements if then else Will be executed if is FALSE.

Pascal Programming Today Chapter 4 5 Flowchart of an if-then-else statement

Pascal Programming Today Chapter 4 6 »Sometimes, more than one statement is required to be executed under the condition. »In such case, a compound statement should be used.

Pascal Programming Today Chapter 4 7 »A compound statement consists of two or more simple statements enclosed by a pair of reserved words begin and end.

Pascal Programming Today Chapter 4 8 Syntax of if-then-else statements with compound statements if then begin ;  end else begin ;  end Compound statement

Pascal Programming Today Chapter 4 9 Flowchart of an if- then-else statement with compound statements

Pascal Programming Today Chapter 4 10 If-then Statements Syntax of if-then statements if then

Pascal Programming Today Chapter 4 11 Flowchart of an if-then statement

Pascal Programming Today Chapter 4 12 Syntax of if-then statements with compound statements if then begin ;  end

Pascal Programming Today Chapter 4 13 Flowchart of an if-then statement with compound statement

Pascal Programming Today Chapter 4 14 Nested If Statements »An if statement may be nested by another if statement to form a nested if statement.

Pascal Programming Today Chapter 4 15 Syntax of nested if statements if then if then else else if then else

Pascal Programming Today Chapter 4 16 Flowchart of a nested if statement

Pascal Programming Today Chapter 4 17 »Reserved word else should be matched to the nearest preceding if in nested if statements.

Pascal Programming Today Chapter 4 18 Case Statements »A case statement is preferred for selection involving more than three alternatives.

Pascal Programming Today Chapter 4 19 Syntax of case statements case of : ;  : end A variable or an expression of ordinal data types ( integer, char or Boolean ).

Pascal Programming Today Chapter 4 20 Syntax of case statements case of : ;  : end Lists of possible values of.

Pascal Programming Today Chapter 4 21 Syntax of case statements case of : ;  : end Simple or compound statements.

Pascal Programming Today Chapter 4 22 »Only one selection on the list of statements will be executed. »No statements will be executed if no case label match the selector.

Download ppt "Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:"

Similar presentations