Jumping Statements
Jumping Statements
Unconditional Branching
Harapriya Mohanta
Jumping Statements
What is Jumping Statements?
Why do we use them?
Where used?
Harapriya Mohanta
Jumping Statements
What is Jumping Statements?
Why do we use them?
Where used?
Harapriya Mohanta
Jumping Statements
What is Jumping Statements? Jumping statements are those
Why do we use them? statements which make the control
jump to another section of the
Where used? program unconditionally when
encountered.
Harapriya Mohanta
Jumping Statements
What is Jumping Statements?
Why do we use them?
• It is used to terminates the loop
Where used? or switch-case instantly.
• It is also used to escape /skip the
execution of a section of the
program.
Harapriya Mohanta
Jumping Statements
What is Jumping Statements?
Why do we use them?
Where used?
• inside loops /switch statement
Harapriya Mohanta
Harapriya Mohanta
Break Statement:
Harapriya Mohanta
Break Statement:
switch (expression)
{
case label1:
// statements
break;
case label2:
// statements
break;
.
.
.
default: // default is optional
// default statements
}
Harapriya Mohanta
Example to understand how break statement works in C
#include <stdio.h>
Output:-
1
int main()
2
{
3
int i;
4
for (i = 1; i <= 10; i++)
5
{
printf("%d\n", i);
if (i == 5)
break;
}
return 0;
}
Harapriya Mohanta
Break Statement in nested loops:
break;
Harapriya Mohanta
Continue Statement:
• It is used in looping to skip some statements.
• It is used inside loop along with the decision-making statements.
• When continue statement encounters, the lexecution will go to the starting of the
loop.
• The statement below continue statement will not be executed, if the given
condition becomes true.
Harapriya Mohanta
Example to understand how continue statement works in C
#include <stdio.h>
Output:-
1
int main()
2
{
4
int i;
5
for (i = 1; i <= 5; i++)
{
if (i == 3)
continue;
printf("%d\n", i);
}
return 0;
}
Harapriya Mohanta
Continue Statement in nested loop:
Harapriya Mohanta
goto Statement:
• goto jump statement is used to transfer the flow of control to any part of the program
desired.
• The programmer needs to specify a label or identifier with the goto statement in the
following manner:
goto label;
This label indicates the location in the program where the control jumps to.
Disadvantages
Harapriya Mohanta
Example of goto Statement:
Return jump statement is usually used at the end of a function to end or terminate it
with or without a value. It takes the control from the calling function back to the main
function(main function itself can also have a return).
Harapriya Mohanta