blogger Indonesia

Follow judhyns blog

THE continue STATEMENT

Introduction

The break statement breaks the entire loop, but a continue statement breaks the current iteration. After a continue statement, the control returns to top of the loop, that is, to the test conditions. Switch doesn't have a continue statement.

Program/Example

Suppose you want to print numbers 1 to 10 except 4 and 7. You can write:

for(i = 0, i < 11, i++) {    if ((i == 4) || (i == 7)) continue;    printf(" the value of i is %d\n", i); } 

Explanation

  1. If i is 1 then the if condition is not satisfied and continue is not executed. The value of i is printed as 1.

  2. When i is 4 then the if condition is satisfied and continue is executed.

  3. After executing the continue statement, the next statement, (printf), is not executed; instead, the updated part of the for statement (i++) is executed.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |