PRESENTATION ON FOR LOOP

544 views
479 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
544
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

PRESENTATION ON FOR LOOP

  1. 1. FOR LOOP PRESENTED BY:  FAROOQ MUSTAFA JOYIA (169-FET/BSME/F11-B) DEPARTEMENT OF MECHANICAL ENGINEERING FACULTY OF ENGINEERING AND TECHNOLOGYINTERNATIONAL ISLAMIC UNIVERSITY ISLAMABAD
  2. 2. AGENDA WHAT IS LOOPING? GENERAL FORM OF FOR LOOP DESCRIPTION OF GENERAL FORM EXECUTION NESTING THE LOOP MULTIPLE ASSIGNMENTS IN FOR LOOP NULL STATEMENT
  3. 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. 4. GENERAL FORM General form of for statement is for(expression1;expression2;expression3) { Statement1; Statement2; . . . }
  5. 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. 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. 7. EXPRESSION 3  This is some kind ofexpression for altering the value of control variable.  e.g. i++
  8. 8. EXECUTION OF FOR LOOP When the loop is started normally a control variable is initialized by executing. Expression_2 is tested if it is false then control is transferred outside the loop otherwise do next step_3. Body of loop is executed. Value of control is altered by expression 3. Step 2 and 4 are repeated until condition becomes false.
  9. 9. NESTING THE LOOPS When a for loop is completely embedded within for loop, the structure is called nested for loop.
  10. 10. Inner for loop must finish first than outer loop must start another iteration, if the specified condition is still met.
  11. 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. 12.  main(){ int x,y; for(x=1,y=10;x<=10;x++,y--) printf (“x=%dt y=%dn:,x,y);
  13. 13. NULL STATEMENT The for statement does not end with a semicolon. The for statement has within it either a statement block that ends with the closing brace or a single statement that ends with a semicolon.
  14. 14. THE END

×