C Progrmming Class 5
C Progrmming Class 5
Control Statements
Content
• If Condition
• If Else Condition
• If Else If Condition
• Switch Statement
• Loop
• Types of loop
If Condition
• If the condition is true its body execute otherwise does not execute.
Example:-
Int a = 50, b = 60;
If(a>b){
Printf(“a is greater then b”);
}
Printf(“Hello world”);
If Else Condition
• If the condition is true if part execute and if the condition is false else part execute .
Example:-
Int a = 50, b = 60;
If(a>b){
Printf(“a is greater then b”);
}else{
Printf(“b is greater then a”);
}
Printf(“Hello world”);
If Else If Condition
• It is a part of conditional statement that executes only one condition at a time.
• If all conditions are false then the else part execute.
• It execute that condition that become first true from the top.
If (){
Printf(“Statement 1”);
}else if (){
Printf(“Statement 2”);
}else{
Printf(“Else Statement”);
Switch Statement
• Switch statement allows us to execute one statement from
many statement and that statement are called case, actually
in switch statement inside the body of a switch number of
cases are used and a parameter are passed and from which
case this parameter is matched, executed.
• In the switch statement a value / number is passed in the
place of parameter in the place of parameter and that case
will execute which is equal to that value/ number.
• If no case matched with parameters then default case will
execute.
Loop
• To run the body continuously until the a required condition
is fulfill is called the loop. It us used to perform looping
operation. When the condition will become false the
execution of loop will be stopped.
Types of loop
• For Loop
• While loop
• Do While loop
• Nested Loop
For Loop
• In for loop there are three part initialization, condition,
increment/ decrement
• Initialization part executes only once.
• All the three parts of loop are optional.
• Example :-
For (int i=1; I,=10; i++){
Printf(“%d\n”, i);
}
While loop
• Its body will execute until the given condition is true.