Jump statements in C++ are powerful tools that control the flow of execution in a program. These statements—break, continue, goto, and return—allow developers to manage loops, conditionals, and function behaviors more efficiently.
By mastering these statements, you can write cleaner and more controlled C++ programs!
2.continue
3.goto
4.return
The break statement is used to exit a loop or a switch statement prematurely, i.e., to terminate the current iteration and stop the loop completely.
——————–
#include <iostream>
using namespace std;
int main() {
for()
if (m == 3) {
break;
}
cout << m<< ” “;
}
cout << “Loop terminated\n”;
return 0;
}
———————————–
#include <stdio.h>
int main() {
printf(“Enter the choice”);
scanf(“%d”,&num);
switch(num)
{
case 1:
cout<<”iam in case”;
break;
case 2:
cout<<”iam in case2″;
break;
default:
cout<<“iam default”;
}
}
The continue statement is used to skip the current iteration of a loop and move to the next iteration of the loop immediately. It only affects the loop in which it is used.
Example2:
#include <stdio.h>
int main() {
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue; // Exit the loop when i is 3
}
cout<< i;
}
cout<<“Loop terminated\n”;
return 0;
}
Example:
#include<iostream>
int main()
{
int x=0;
if(x<5)
{
goto label;
}
Cout<<”this printf is not printed”;
label:
cout<<”iies”;
}
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b; // Return the sum of a and b
}
int main() {
int result = add(3, 4);
cout << “Sum: ” << result << endl;
return 0;
}
Indian Institute of Embedded Systems – IIES