![]() |
| Jump Statements in C++ Programming | break, continue, goto, return |
Jump Statement in C++
Jump Statement: A jump statement in Java is a control flow statement that allows the program to jump to a different part of the code. It is used to transfer the control from one point to another point in the program.
What are Jump Statements in C++
- break Statement in C++
- continue Statement in C++
- goto Statement in C++
- return Statement in C++
Break Statement in C++ Example
Break Statement: A break statement can be used to exit a loop or switch statement prematurely. It is used to transfer the control out of the body of loop. In other word we can say that it terminates the current loop. Break statement are mostly used with loop(for, while, do while) and switch statement.
The break statement immediately exits the current loop or loop or switch statement. Break terminates the entire loop and transfer control to the statement after the loop.
Syntax of break Statement in C++
{ if(condition){ break; } body Statements; } |
How to Take Float User Input in C++
int main(){ for(int i=1;i<=5;i++) { if(i==4){ break; } cout<<"Your Number is:"<<i<<endl; } } ============OUTPUT============ Your Number is:1 Your Number is:2 Your Number is:3 |
Example of Without Using Break Statement
int main(){ for(int i=1;i<=5;i++) { cout<<"Your Number is:"<<i<<endl; } } ============OUTPUT============ Your Number is:1 Your Number is:2 Your Number is:3 Your Number is:4 Your Number is:5 |
Continue Statement in C++ Example
Continue Statement: A continue statement can be used to skip the current iteration of a loop and proceed to the next iteration. It is used to skip the next statement and continue the loop. Continue statement are mostly used with loop(for, while, do while). The continue statement skips the current iteration and moves to the next one. Continue is a skip remaining statement in current iteration and move to the next iteration.
Syntax of Continue Statement in C++
{ if(condition){ continue; } body Statements; } |
Continue Statement Example Program in C++
int main(){ for(int i=1;i<=5;i++) { if(i==3){ continue; } cout<<"Your Number is:"<<i<<endl; } } ============OUTPUT============ Your Number is:1 Your Number is:2 Your Number is:4 Your Number is:5 |
Example of Continue Statement in C++
int main(){ int s; for(int s=1;i<=10;i++) { if(s%3==0){ continue; } cout<<"Check Homework of Student:"<<s<<endl; } } ============OUTPUT============ Check Homework of Student:1 Check Homework of Student:2 Check Homework of Student:4 Check Homework of Student:5 Check Homework of Student:7 Check Homework of Student:8 Check Homework of Student:10 |
Define Goto Statement in C++
Goto Statement: A goto statement can be used to alter the normal sequence of program execution by transferring control to some other part of the program. In its general for the goto statement is written as goto label. The goto statement provides an unconditional jump from one point to another point in the program. While its part of the C language its use is generally discouraged in modern programming due to its impact on code readability and maintainability.Syntax of Goto Statement in C++
//Label Definition Label: body Statements; |
Example of Goto Statement in C++ Language
int main(){ int n,i=1; cout<<"Enter any number:"; cin>>n; table: cout<<n<<"X"<<i<<"="<<n*i<<endl; i++; if(i<=10) goto table; } ============OUTPUT============ 8 X 1=8 8 X 2=16 8 X 3=24 8 X 4=32 8 X 5=40 8 X 6=48 8 X 7=56 8 X 8=64 8 X 9=72 8 X 10=80 |
Return by Reference in C++ with Example
Return Statement: A return can be used to exit from a method and optionally return a value to the method caller. Return statement terminates the current function and transfer the control to the calling function. We can also use return statement to transfer value from one function to another.
Example of Return Statement in C++
int Jiocoding(){ int a=30,b=5; int c=a*b; return c; } int main(){ int res=Jiocoding(); cout<<"Result is:"<<res; } ============OUTPUT============ Result is:150 |

