C - Jumping Statements
Jumping Statements:
1. break
2. continue
3. goto
4. exit
The break statement provides an early exit
from for, while, and do, just as from switch. A break causes the innermost enclosing
loop or switch to be exited immediately.
SYNTAX-
break;
EXAMPLE-
/* Example of break */
main()
{
int
a;
for
(a=1;a<6;a++)
{
If
(a==4)
{
break;
}
printf
(“%d”,a);
}
}
Output-
1
2
3
The continue statement is used to bypass the remainder
of the current pass through a loop. That is, it passes the flow of control to
the next iteration within for, while or do loops.
In the while and do, this means that the test
part is executed immediately; in the for, control passes to the increment step.
The continue statement applies only to loops, not to switch.
SYNTAX- continue;
EXAMPLE-
/*
Example of continue */
main()
{
int
a;
for
(a=1;a<6;a++)
{
If
(a==4)
continue;
printf
(“%d”,a);
}
}
Output-
1
2
3
5
SYNTAX-
goto label name;
EXAMPLE-
/*
Example of goto */
main()
{
int
a=1;
one:
printf(“%d\n”,a);
a++;
if
(a<=4)
{
goto
one;
}
}
Output-
1
2
3
4
SYNTAX-
exit();
EXAMPLE-
/*
Example of exit */
main()
{
int
a;
for
(a=1;a<=6;a++)
{
if
(a==4)
exit();
printf(“Bye”);
}
}
Output-
Bye
Bye
Bye
Comments
Post a Comment