0
How it works?
please, someone, explain me how works "break;" in the loop, and why it's needed
4 Answers
+ 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.
+ 1
Big thanks!
0
I don't know how it works so please help me too mo
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.
}