SlideShare a Scribd company logo
1 of 4
Jumping Statements: The jump statement unconditionally transfer program control within a
function. C language provides us multiple statements through which we can transfer the control
anywhere in the program.
There are basically 3 Jumping statements:
1. break jumping statements.
2. continue jumping statements.
3. goto jumping statements.

break statement: Sometimes, it is necessary to exit immediately from a loop as soon as the
condition is satisfied. The break statement terminates the execution of the enclosing loop or
conditional statement. In a for loop statement, the break statement can stop the counting when a
given condition becomes true. The break statement is a jump instruction and can be used inside a
switch construct, for loop, while loop and do-while loop. The execution of break statement
causes immediate exit from the concern construct and the control is transferred to the statement
following the loop. In the loop construct the execution of break statement terminates loop and
further execution of the program is reserved with the statement following the body of the loop
When break statement is used inside a loop, then it can cause to terminate from a loop. The
statements after break statement are skipped.

Syntax:
The syntax for a break statement in C is as follows:
break;

The break statement in C programming language has the following two usages:
1. When the break statement is encountered inside a loop, the loop is immediately
terminated and program control resumes at the next statement following the loop.
2. It can be used to terminate a case in the switch statement (covered in the next chapter).
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the
execution of the innermost loop and start executing the next line of code after the block.
You can see in the given example that the program is supposed to count the numbers from 1 to
20 using for loop. As per the condition defined the break statement stop the execution of the loop
as soon as it detects the number 5 .
#includes <stdio.h>
#include <conio.h>
void main () {
clrscr(); int n;
for (n=1; n<20; n++) {
printf("%dn", n);
getch();
if (n==5)
break;
}
}

continue statement
The continue statement in C programming language works somewhat like the break statement.
Instead of forcing termination, however, continue forces the next iteration of the loop to take
place, skipping any code in between.
For the for loop, continue statement causes the conditional test and increment portions of the
loop to execute. For the while and do...while loops, continue statement causes the program
control passes to the conditional tests.

Syntax:
The syntax for a continue statement in C is as follows:
continue;

The continue statement provides a convenient way to force an immediate jump to the loop
control statement. The break statement terminates the execution of the loop. As you can see in
the given example, we have used both the statements within the do while loop. The program
prompts the user to enter any number. If the number is less than 0, the break statement
terminates the execution of the loop. If the number is greater than 10, the continue statement
skips the value and jumps to the do while loop without terminating the loop. Otherwise, it will
print the entered number.
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
clrscr();
for(i=1; i<=10; i++)
{
if(i==6)
continue;
printf("nt %d",i); // 6 is omitted
}
getch();}

goto Statement :
It is a well known as 'jumping statement.' It is primarily used to transfer the control of execution
to any place in a program. It is useful to provide branching within a loop.
When the loops are deeply nested at that if an error occurs then it is difficult to get exited from
such loops. Simple break statement cannot work here properly. In this situations, goto statement
is used. A goto statement in C programming language provides an unconditional jump from the
goto to a labeled statement in the same function.

Syntax:
The syntax for a goto statement in C is as follows:
goto label;
..
.
label: statement;

Here label can be any plain text except C keyword and it can be set anywhere in the C program
above or below to goto statement.
#include<stdio.h>
void main()
{
int a;
start:
printf("enter any no.");
scanf("%d", &a);
if(a<0)
goto start; a=a*a;//Goto statement A
printf("n %d", a);
getch();
}

More Related Content

What's hot

What's hot (20)

Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Loops in c
Loops in cLoops in c
Loops in c
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
C functions
C functionsC functions
C functions
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Type conversion
Type conversionType conversion
Type conversion
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Input output streams
Input output streamsInput output streams
Input output streams
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 

Similar to Jumping statements

Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
rurumedina
 

Similar to Jumping statements (20)

Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdf
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Operators
OperatorsOperators
Operators
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
 
C language 2
C language 2C language 2
C language 2
 
Control structures
Control structuresControl structures
Control structures
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 

More from Suneel Dogra (20)

Business model
Business modelBusiness model
Business model
 
Internet
InternetInternet
Internet
 
Html
HtmlHtml
Html
 
Dreamweaver
DreamweaverDreamweaver
Dreamweaver
 
Advanced html
Advanced htmlAdvanced html
Advanced html
 
Sql
SqlSql
Sql
 
File organisation
File organisationFile organisation
File organisation
 
Distributed databases
Distributed databasesDistributed databases
Distributed databases
 
Database models
Database models Database models
Database models
 
Data base management system
Data base management systemData base management system
Data base management system
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1
 
Web sitedesignpart1
Web sitedesignpart1Web sitedesignpart1
Web sitedesignpart1
 
Internet security
Internet securityInternet security
Internet security
 
What is the linux
What is the linuxWhat is the linux
What is the linux
 
He 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know aboutHe 12 different types of servers that every techie should know about
He 12 different types of servers that every techie should know about
 
Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014Bachelor of computer application b.c.a.-2014
Bachelor of computer application b.c.a.-2014
 
Cloud computing application
Cloud computing applicationCloud computing application
Cloud computing application
 
Fast track to linux
Fast track to linuxFast track to linux
Fast track to linux
 
A sorted linear array
A sorted linear array A sorted linear array
A sorted linear array
 
String in c
String in cString in c
String in c
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Jumping statements

  • 1. Jumping Statements: The jump statement unconditionally transfer program control within a function. C language provides us multiple statements through which we can transfer the control anywhere in the program. There are basically 3 Jumping statements: 1. break jumping statements. 2. continue jumping statements. 3. goto jumping statements. break statement: Sometimes, it is necessary to exit immediately from a loop as soon as the condition is satisfied. The break statement terminates the execution of the enclosing loop or conditional statement. In a for loop statement, the break statement can stop the counting when a given condition becomes true. The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop. The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. In the loop construct the execution of break statement terminates loop and further execution of the program is reserved with the statement following the body of the loop When break statement is used inside a loop, then it can cause to terminate from a loop. The statements after break statement are skipped. Syntax: The syntax for a break statement in C is as follows: break; The break statement in C programming language has the following two usages: 1. When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop. 2. It can be used to terminate a case in the switch statement (covered in the next chapter). If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.
  • 2. You can see in the given example that the program is supposed to count the numbers from 1 to 20 using for loop. As per the condition defined the break statement stop the execution of the loop as soon as it detects the number 5 . #includes <stdio.h> #include <conio.h> void main () { clrscr(); int n; for (n=1; n<20; n++) { printf("%dn", n); getch(); if (n==5) break; } } continue statement The continue statement in C programming language works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control passes to the conditional tests. Syntax: The syntax for a continue statement in C is as follows: continue; The continue statement provides a convenient way to force an immediate jump to the loop control statement. The break statement terminates the execution of the loop. As you can see in the given example, we have used both the statements within the do while loop. The program prompts the user to enter any number. If the number is less than 0, the break statement terminates the execution of the loop. If the number is greater than 10, the continue statement
  • 3. skips the value and jumps to the do while loop without terminating the loop. Otherwise, it will print the entered number. #include <stdio.h> #include <conio.h> void main() { int i; clrscr(); for(i=1; i<=10; i++) { if(i==6) continue; printf("nt %d",i); // 6 is omitted } getch();} goto Statement : It is a well known as 'jumping statement.' It is primarily used to transfer the control of execution to any place in a program. It is useful to provide branching within a loop. When the loops are deeply nested at that if an error occurs then it is difficult to get exited from such loops. Simple break statement cannot work here properly. In this situations, goto statement is used. A goto statement in C programming language provides an unconditional jump from the goto to a labeled statement in the same function. Syntax: The syntax for a goto statement in C is as follows: goto label; .. . label: statement; Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement.
  • 4. #include<stdio.h> void main() { int a; start: printf("enter any no."); scanf("%d", &a); if(a<0) goto start; a=a*a;//Goto statement A printf("n %d", a); getch(); }