Successfully reported this slideshow.
Upcoming SlideShare
×

Branching in C

335 views

Published on

Branching in C For S Teacher

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Branching in C

1. 1. CONTROL CONSTRUCTS
2. 2. Control Constructs Control constructs are of two types 1. DECISION MAKING STATEMENTS 2.LOOPING STATEMENTS
3. 3. Control constructs are Decision making statements 1. If statement 2.If else statement 3. Nested if else statement 4.Switch case Looping statements 5.For loop 6.While loop 7.Do while loop
4. 4. If statement: if (condition) statement; or if (condition) { compound statement; }
5. 5. Example of if statement: int i; printf ("Type in an integer"); scanf ("%ld", &i); if (i == 0) { printf ("The number was zero"); } if (i > 0) { printf ("The number was positive"); } if (i < 0) { printf ("The number was negative"); }
6. 6. If else statement: if (condition) statement1; Else statement2; Or if (condition) { statements1 ; } Else { statements2 ; } If - else ? else if
7. 7. Example of if-else statement: int i; scanf ("%d",i); if (i > 0) { printf ("That number was positive!"); } else { printf ("That number was negative or zero!"); }
8. 8. Nested if else statement: if ((cond.) && (cond.)) { statement; } OR if (cond.) { if (cond.) { statement; } }
9. 9. Example of nested-if statement: if ((i > 2) && (i < 4)) { printf ("i is three"); } or: if (i > 2) { if (i < 4) { printf ("i is three"); } }
10. 10. SWITCH & BREAK switch (integer value) { case 1: statement1; break; /* optional line */ case 2: statement2; break; /* optional line */ .... default: default statement break; /* optional line */ } Switch case statement: