0% found this document useful (0 votes)
22 views18 pages

Jumping Statements

Jumping statements are programming statements that change the normal sequential flow of control by transferring it unconditionally to another part of the program. They are used to terminate loops or switch statements early, skip sections of code, or perform backward and forward jumps in a program. Common jumping statements include break, continue, goto, and return.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views18 pages

Jumping Statements

Jumping statements are programming statements that change the normal sequential flow of control by transferring it unconditionally to another part of the program. They are used to terminate loops or switch statements early, skip sections of code, or perform backward and forward jumps in a program. Common jumping statements include break, continue, goto, and return.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

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:

• It is used to terminate the loop and resume the program


execution from next statement following the loop.
• If we want to use break statement ide loop,we have to
use it along with if statement.
• It is also used to teminate the switch case execution.

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:

It is used to skip some part of the loop for a particular runs.

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

You should avoid By using the goto


goto to use in your statement, we can perform
program because it backward jump as well as
makes the program forward jump
less readable and
complicated.

Harapriya Mohanta
Example of goto Statement:

backward jump forward jump

// print numbers from 1 to n using goto // divide two numbers


#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
int num; int num1, num2;
int i =1; //for printing no printf(“enter two numbers:”);
printf(“enter a number upto which you want to print:”); scanf(“%d %d”,&num1, &num2);
scanf(“%d”,&num); if(num1==0 || num2==0)
count: //label goto end; //jump to end label
printf(“%d”,i); printf(“division is: %d”, (num1/num2));
i++; end:
if(i<=num) printf(“end of program”);
goto count; //jump to count label return 0;
return 0; }
}
Harapriya Mohanta
return 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

You might also like