Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
107 views
in Control Statements by (29.8k points)
closed by

“We know that the execution of a program is sequential”. Is it possible to change this sequential manner and explain different jump statements in detail

1 Answer

+1 vote
by (29.6k points)
selected by
 
Best answer

The execution of a program is sequential but we can change this sequential manner by using jump statements. The jump statements are 

1. goto statement: 

By using goto we can transfer the control anywhere in the program without any condition. The syntax is goto label; 

Example:

#include<iostream>

using namespace std;

int main()

{

float a,b;

cout<<"Enter 2 numbers";

cin>>a>>b;

if(b==0)

  goto end;

cout<<"The quotient is "<<a/b;

return 0;

end:cout<<"Division by zero error";

}

2. break statement: 

It is used to skip over a part of the code i.e. we can premature exit from a loop such as while, do-while, for or switch.

Syntax:

while (expression)

{

if (condition)

break;

}

Eg.

#include<iostream>

using namespace std;

main()

{

int i=1;

while(i<10)

{

     cout<<i<<endl;

     if(i==5)

      break;

     i++;

}

}

The output is

1

2

3

4

5

3. continue statement: 

It bypasses one iteration of the loop.

Syntax:

while (expression)

{

if (condition)

break;

}

Eg.

#include<iostream>

using namespace std;

main()

{

int i=0;

while(i<10)

{

  i++; 

 if(i==5)continue;

 cout<<i<<endl;

}

}

The output is

1

2

3

4

5

6

7

8

9

10

4. exit(0) function: 

It is used to terminate the program. For this the header file cstdlib must be included.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...