Using break with condition statements for looping | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Using break with condition statements for looping

How do we use break in looping

21st Jun 2018, 4:04 AM
Kanana Kanana
Kanana Kanana - avatar
2 Respostas
+ 1
hi kanana so basically the break statement will stop the loop for example in c++ with do while and if all together. int main () { // Local variable declaration: int a = 10; // do loop execution do { cout << "value of a: " << a << endl; a = a + 1; // it will add 1 to a every time. if( a > 15) { // terminate the loop when the condition is true break; } } while( a < 20 ); return 0; } } output:- value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 hope that helps also check this link by Microsoft. https://msdn.microsoft.com/en-us/library/37zc9d2w.aspx
21st Jun 2018, 4:33 AM
MECHANICAL-CELL
MECHANICAL-CELL - avatar
0
you put some condition to break the loop example while( i<100) { Console.write(i}; if(i==50) break; i++ } here loop will break when i hit 50. hope this helps.
21st Jun 2018, 4:24 AM
Sumesh