Professional Documents
Culture Documents
Programming Sec 6
Programming Sec 6
Section - 6
Switch
3
Switch
4
Switch
switch( variable_Name ) {
case value1 :
Statements;
break;
case value2 :
Statements;
break;
default:
statements;
}
5
Switch
6
Switch
int expression = 2;
switch (expression) {
case 1:
printf("Case 1");
case 2:
printf("Case 2");
case 3:
printf("Case 3");
default:
printf("Default case");
}
7
Example 1:
8
Answer:
9
Answer
10
Example 2:
11
Answer
12
Task:
13
Answer
14
For loop
15
For Loop
• Loops are handy, if you want to run the same code over and
over again, each time with a different value.
16
For
18
Answer
19
Example 5:
20
Example 6:
Write a program to print the sum of even numbers from 0 to 100 ?
21
Another solution
22
Example 7:
23
Answer
24
Example 8:
25
Answer
26
THANK YOU