0

How it works?

please, someone, explain me how works "break;" in the loop, and why it's needed

7th Jan 2017, 7:37 AM
rurwww
4 Respostas
+ 8
break; is used to immediately exit/close a loop or switch For example : int x = 1; while (x < 10); { Console.WriteLine(x++); if ( x == 4){ break; } } THis code will output '2' , '3' , '4' . Once it reaches 4, it goes into the 'if' statement and proceeds to the 'break' . The 'break' will then just close the loop.
7th Jan 2017, 8:28 AM
Wen Qin
Wen Qin - avatar
+ 1
Big thanks!
7th Jan 2017, 8:35 AM
rurwww
0
I don't know how it works so please help me too mo
7th Jan 2017, 8:00 AM
adi
adi - avatar
0
"break" Just exit loop execution... If you have two loops and brake on internal, the first loop execute. e.g for (int x=default(int); x < 10; x++) { for (int y=default(int); y < 10; y++) { //break loop. break; } // here, the first loop continues. }
7th Jan 2017, 3:53 PM
Roberto De Almeida
Roberto De Almeida - avatar