For loop:
These statements change the normal execution of program and jumps over the specific part of program.
Following are the jumps statements used in C++.
break
continue
goto
return
exit ()
The break statement allows you to exit a loop or a switch statement from any point within its body, bypassing its normal termination expression. It can be used within any C++ structure.
Break example:
Copy code
#include<iostream>
using namespace std;
int main()
{
int count;
for(count = 1; count <= 100; count++)
{
cout << count;
if(count = 10) // This line seems to have an error: it should be ‘if (count == 10)’
break;
}
return 0;
}
The continue statement is just the opposite of the break statement. Continue forces the next iteration of the loop to take place, skipping the remaining statements of its body.
Continue example:
#include<iostream>
using namespace std;
int main()
{
// The rest of the continue example code is missing from this extraction
}
{
int count;
for(count = 1; count <= 10; count++)
{
if(count = 5)
continue;
cout << count;
}
return 0;
}
In C++ programming, the goto statement is used for altering the normal sequence of program execution by transferring control to some other parts of the program.
Goto example:
#include<iostream>
using namespace std;
int main()
{
float num, average, sum = 0.0;
int i, n;
cout << “Maximum number of inputs: “;
cin >> n;
for(i = 1; i <= n; i++)
{
cout << “Enter number” << i << “: “;
cin >> num;
if(num < 0.0)
{
// Control of the program move to jump:
goto jump;
}
sum += num;
}
Jump:
average = sum / n;
}
cout << “\n Average = ” << average;
return 0;
}
The return statement returns the flow of the execution to the function from where it is called. This statement does not mandatorily need any conditional statements. As soon as the statement is executed, the flow of the program stops immediately and returns the control from where it was called.
Syntax:
return (expression / value)
The exit function, declared in <stdlib.h>, terminates a C++ program. The value supplied as an argument to exit is returned to the operating system as the program’s return code or exit code.
Syntax:
void exit (int);
0 of 8 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 8 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Which loop in C++ is known as an entry controlled loop?
What type of loop in C++ is guaranteed to execute at least once, even if the condition fails for the first time?
Which loop statement in C++ is considered a post-test loop?
Which loop statement in C++ is considered a post-test loop?
What does the break statement do in C++?
What is the purpose of the continue statement in C++?
Which jump statement in C++ is used for altering the normal sequence of program execution by transferring control to some other parts of the program?
What does the return statement do in C++?