Professional Documents
Culture Documents
CSE - 105 - Lec 5 (If Else, Switch Case Statement)
CSE - 105 - Lec 5 (If Else, Switch Case Statement)
Language
1
Objectives of the Course
❏ To understand the basics of Computers.
❏ To understand the basics of computer programming in C.
❏ To think and analyze about problem
❏ To solve elementary programming problems.
Lec 5: IF ELSE in C
10/17/2022 6
Single If in C
if (expression)
{
statement;
…………
statement;
}
Syntax
Single if
Code Output
Sequence of only “If”s Need to check multiple condition one after another
(usually on same vars, might be true for multiple cases)
If and else Only two conditions, only one of them might be true.
Second condition doesn’t even need to be checked.
If- else-if- else Ladder Only one condition out of multiple may be true. Check
them one after another. The last or default condition is
not checked and written with an “else”
break;
case constant 2: // statements
break;
...
default: // default statements
}
10/17/2022 25