Presentation is loading. Please wait.

Presentation is loading. Please wait.

for, do-while and switch statments

Similar presentations


Presentation on theme: "for, do-while and switch statments"— Presentation transcript:

1 for, do-while and switch statments
© 2016 Pearson Education, Ltd. All rights reserved.

2 for Iteration Statement
The for iteration statement handles all the details of counter-controlled iteration. © 2016 Pearson Education, Ltd. All rights reserved.

3 for Iteration Statement (Cont.)
General Format of a for Statement The general format of the for statement is for (initialization; condition; increment) { statement } for (j = 1; j <= 40; j ++){ printf(“%d\n”,j); © 2016 Pearson Education, Ltd. All rights reserved.

4 do…while Iteration Statement
The do…while iteration statement is similar to the while statement. In the while statement, the loop-continuation condition is tested at the beginning of the loop before the body of the loop is performed. The do…while statement tests the loop- continuation condition after the loop body is performed. © 2016 Pearson Education, Ltd. All rights reserved.

5 do…while Iteration Statement (Cont.)
do{ statement }while (condition); © 2016 Pearson Education, Ltd. All rights reserved.

6 © 2016 Pearson Education, Ltd. All rights reserved.
break and continue continue Statement The continue statement, when executed in a while, for or do…while statement, skips the remaining statements in the body of that control statement and performs the next iteration of the loop. Break Statement The break statement, when executed in a while, for or do…while statement, terminates the loop. © 2016 Pearson Education, Ltd. All rights reserved.

7 © 2016 Pearson Education, Ltd. All rights reserved.
 switch statement Transfers control to one of the several statements, depending on the value of a condition. switch(x) { case 1 : printf(“1”); break; case 2 : printf(“2”); break; case 3 : printf(“3”); break; } © 2016 Pearson Education, Ltd. All rights reserved.


Download ppt "for, do-while and switch statments"

Similar presentations


Ads by Google