By using break,you can force immediate termination of a loop, bypassing the conditional expression and any remaininh code in the body of the loop.When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
The continue statement performs such an action. In while and do-while loops, a continue statement causes control to be transferred directly to the conditional expression that controls the loop.
This C++ program uses a for loop to iterate from 0 to 9 (inclusive) and print the values of the loop variable i, except when i equals 4. When i equals 4, the loop is exited prematurely using the break statement. Here's a breakdown of the program's logic:
#include<iostream> using namespace std; int main() { for(int i=0;i<10;i++) { if (i==4) { break; } cout<<i<<"\n"; } return 0; }To download raw file Click Here
0 1 2 3
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions