PRESENTATION ON FOR LOOP

15

Transcript of PRESENTATION ON FOR LOOP

  • 1. FOR LOOP PRESENTED BY: FAROOQ MUSTAFA JOYIA(169-FET/BSME/F11-B)DEPARTEMENT OF MECHANICAL ENGINEERINGFACULTY OF ENGINEERING AND TECHNOLOGYINTERNATIONAL ISLAMIC UNIVERSITY ISLAMABAD

2. AGENDA WHAT IS LOOPING? GENERAL FORM OF FOR LOOP DESCRIPTION OF GENERAL FORM EXECUTION NESTING THE LOOP MULTIPLE ASSIGNMENTS IN FORLOOP NULL STATEMENT 3. WHAT IS LOOPING? LOOPING,also called iteration, is used in programming to perform the same set of instructions over andover until certain specified conditions are satisfied. Here we will discuss about for loop 4. GENERAL FORM General form of for statement isfor(expression1;expression2;expression3) { Statement1; Statement2; . . . } 5. EXPRESSION 1 Thisis some kind of expression which initializes the control variable. This statement is only carried out once before the starting of for loop. 6. EXPRESSION 2 Thisexpression is evaluated at the beginning of for loop and the loop is only carried out when this expression is true. 7. EXPRESSION 3 This is some kind ofexpression for altering the value of control variable. e.g. i++ 8. EXECUTION OF FOR LOOP When the loop is startednormally a control variable isinitialized by executing. Expression_2 is tested if it isfalse then control istransferred outside the loopotherwise do next step_3. Body of loop is executed. Value of control is altered byexpression 3. Step 2 and 4 are repeateduntil condition becomes false. 9. NESTING THE LOOPS Whena for loop is completely embedded within for loop, the structure is called nested for loop. 10. Inner for loop must finish first than outer loop must start another iteration, if the specified condition is still met. 11. MULTIPLE ASSIGNMENTS IN FOR LOOP We can use more than one initialization statement &more than one increment decrement statement. However only one condition is allowed within a for loop. 12. main(){ int x,y; for(x=1,y=10;x