Presentation is loading. Please wait.

Presentation is loading. Please wait.

FLOW OF CONTROL.

Similar presentations


Presentation on theme: "FLOW OF CONTROL."— Presentation transcript:

1 FLOW OF CONTROL

2 FLOW OF CONTROL Contents
1. Statements 2. Selection statements i) if statements ii) switch statement 3. Iteration statements i) for loop ii) while loop iii) do-while 4. Jumb statement i) goto ii) break iii) continue

3 STATEMENTS The instructions given to the computer to perform the action. { statement1 ; statement2 ; . } Statements are terminated with a semicolon. The simplest statement is the Empty or null statement.

4 SELECTION STATEMENT if statement nested ifs if-else-if ladder
switch statement

5 if STATEMENT If the condition evaluates to true, a course-of-action is followed otherwise the course of action is ignored Syntax if(expresssion) { statement; }

6 Nested ifs STATEMENT Syntax if(expresssion1) { -- -- if(expression2)
[else statement2;] } else body of else;

7 if-else-if STATEMENT Syntax if(expresssion1) { statement 1; } else
if(expression2) statement2; statement 3;

8 switch STATEMENT Syntax switch(expresssion) {
case constant 1 : statement sequence 1; break; case constant 2 : statement sequence 2; case constant 3 : statement sequence 3; : case constant -1 : statement sequence n-1; [default : statement sequence n ] }

9 ITERATION STATEMENT Allow a set of instructions to be performed repeatedly until a certain condition is fulfilled for loop while loop do-while loop

10 for Loop Syntax Execute
for(intializationexpression(s); test-expression; update expressions) { body- of – the – loop; } Execute 4th Execute 2nd Execute 1st Execute 3rd

11 while Loop Syntax Initialization expression; while (test-expression) {
statements; : update expressions; }

12 do-while Loop Always execute at least once Syntax
Initialization expression; do { statements; : update expressions; } while (test-expression)

13 JUMP STATEMENT goto statement break statement continue

14 goto STATEMENT goto label; --- label :
Transfer the program control to specified place by a label Syntax goto label; --- label : label is a user supplied identifier and can appear either before or after goto.

15 break STATEMENT Enables a program to skip over part of the code
while (test exprsn) { statement 1; if (val >2000) break; : statement2 } statement3; for(inilialize; test- exprsn; update) { statement 1; if (val >2000) break; : statement2 } statement3; do { statement 1; if (val >2000) break; : statement2 } while(test exprsn) statement3;

16 continue STATEMENT Instead forcing termination, it forces the next iteration of the loop to take place, skipping any code in between while (test exprsn) { statement 1; if (val >2000) continue; : statement2 } statement3; for(inilialize; test- exprsn; update) { statement 1; if (val >2000) continue; : statement2 } statement3; do { statement 1; if (val >2000) continue; : statement2 } while(test exprsn) statement3;

17 Diagrammatic representation
Flow of control Statements Selection Statements Iteration Statements Jump Statement if stme nts switch stmen ts for stmen ts while stmen ts do-while stmen ts goto stmen ts break stmen ts continue stmen ts

18


Download ppt "FLOW OF CONTROL."

Similar presentations


Ads by Google