News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Continue in C

Started by thiruvasagamani, Sep 22, 2008, 10:33 AM

Previous topic - Next topic

thiruvasagamani

Continue statement:

while(condition)
{
-----
-----
-----
if( condition)
continue
-----
-----
-----
}


From the above when continue statement is executed control goes to next iteration of loop. Statements following continue are skipped.This can be used for, while , do-while loops but not in switch.

NOTE:

Break is used to go out of loop.
Continue is used to skip the current iteration

Eg:

main()
{
void f1();
f1();
printf(" back to main");
getch();
}
void f1()
{
int i;
for(i= 1; i<= 7; i++)
{
printf("%d\n", i);
if( i % 3 == 0)
break or continue;
printf(" hello\n");
}
printf(" outside loop");
}


o/p:

1. If we use break for following 'if' statement output is

1
hello
2
hello
3
outside loop
back to main

2. If we use continue for following 'if' statement output is

1
hello
2
hello
3
4
hello
5
hello
6
7
hello
outside loop
back to main

3. If we use return for following 'if' statement output is

1
hello
2
hello
3
back to main
4. If we use exit(0) for following 'if' statement output is

1
hello
2
hello
3





Thiruvasakamani Karnan