break; statement helps in coming out of the current loop
Further in case of nested loop it gets you out of the innermost loop.
// program to print the value of i
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 5; i++) {
// break condition
if (i == 3) {
break;
}
cout << i << endl;
}
return 0;
}
/*Q;Design a program to print the employee IDs starting
from 1 until an Id occur who have resigned. IDs of
resigned persons are 7 and 10 .*/
#include<iostream>
using namespace std;
int main()
{
int meet=0;
for(int i=1;i<30;i++)
{
if(i==7||i==10)
break;
else
meet=1;
cout<<"Employee ID:"<<i<<endl;
}
return 0;
}
Code Example |
---|
Cpp :: tuple vector c++ |
Cpp :: c++ read matttrix from text file |
Cpp :: dice combinations cses solution |
Cpp :: c++ vector |
Cpp :: abstraction in cpp |
Cpp :: looping in map c++ |
Cpp :: how to sort array in c++ stockoverflow |
Cpp :: cknuth hash |
Cpp :: find positive number factorial in C++ |
Cpp :: one away coding question |
Cpp :: bfs sudocode |
Cpp :: use of strstr in c++ |
Cpp :: C++ program to sizes of data types |
Cpp :: max c++ |
Cpp :: char array declaration c++ |
Cpp :: even and odd in c++ |
Cpp :: add input in c++ |
Cpp :: c/c++ windows api socket wrappers |
Cpp :: find an element in vector of pair c++ |
Cpp :: STD::ERASE FUNCTION IN C++ |
Cpp :: copy assignment operator in c++ |
Cpp :: memset in cpp |
Cpp :: and c++ |
Cpp :: split text c++ |
Cpp :: malloc 2d array cpp |
Cpp :: linkedlist in c++ |
Cpp :: vsearch c program stdlib |
Cpp :: pointer to value of others file cpp |
Cpp :: code runner c++ syntax error |
Cpp :: c++ anti debugging |