You are on page 1of 13

COMPUTER PROGRAMMING 1

Conditional
Statement
Conditional Statement
are statements that check an expression then
may or may not execute a statement or group
of statements depending on the result of the
condition.
The if statement
The general form of the if statement
if (expression) is:
statement;
if statement…
where:
if is a reserve word in Turbo C
Expression is a relational or boolean
expression that evaluates to a TRUE(1) or
FALSE(2) value.
Statement may either be a single Turbo C or a
block of Turbo C statements
if statement
The general form of if block statements is:

Ifiif (expression)
{
Statement_sequence;
}
if block statement
• In an if statement, if the expression
evaluates to TRUE(1), the statement or
the block of statements that forms the
target of the if statement will be
executed. Otherwise, the program will
ignore the statement or the block of
statements.
The if-else statement
The general form of the if-else statement is:

If (expression)
statement_1;
else
statement_2;
Where:
if and else are reserve w.ords in Turbo C
if-else statement
Expression is relational or boolean expression that
evaluates to a TRUE(1) or FALSE(2) value
Statement_1 and statement_2 may either be a single Turbo
C statement or a block of Turbo C statements.
The general form is:
If (expression)
{
Statement_sequence;
}
Else
Statement_sequence;
}
A switch  statement

This statement allows a variable to be tested for


equality against a list of values. Each value is called
a case, and the variable being switched on is
checked for each switch case.

You might also like