You are on page 1of 14

Department of Computer Science & Engineering

UNIVERSITY OF MINES AND TECHNOLOGY

COMPUTER PROGRAMMING

BY: DR MILLICENT AGANGIBA


IF statement
‘IF’ statement basis on the result and is used in nests as well
depending on the requirement.
ELSE is used in combination with IF statements to construct a
complete statement or do a computation of more than one
result.
The IF statement is most suitable where there are limited
comparisons to be made. IF statements tend to be lengthy
since the whole logical expression needs to be typed each
time in a program with lots of comparisons.
Single Decision and Action without brackets

if (Boolean expression)
statement(s) /will execute if the Boolean expression is true
Single Decision and Action with braces

if (Boolean expression )
{
statement(s) /will execute if the Boolean expression is true /

}
Either/Or Decision

if (Boolean expression )
{ statement(s) /will execute if the Boolean expression is
true

}
else
{ statement(s) will execute if the boolean expression is false
}
Flow Diagram (if/else)
Multiple Case Decision
int x = 10, y = 20; Multiple Case Decision
if (x != y)
{
if (ix< y)
{
Console.WriteLine(“x is less than y");
}
else if (x > y)
{
Console.WriteLine(“x is greater than y");
}
}
Else
Console.WriteLine(“x is equal to y");
Switch
Flow Diagram (Switch)
Differences between IF ad Switch

You might also like