Its purpose is to interrupt loops loop , looptime, while and for
The break operator interrupts the loop in the body of which it is located, passing control to the line immediately after the interrupted cycle.
Examples and explanations
The application of break in
CODE:
loop ()
{
break;
}
{
break;
}
is tantamount to
CODE:
loop ()
{
goto a;
}
a:;
{
goto a;
}
a:;
The application of break in
CODE:
while (1 == 1)
{
break;
loop ()
{
break;
}
}
while (1 == 1)
{
break;
loop ()
{
break;
}
}
is tantamount to
CODE:
while (1 == 1)
{
goto b;
loop ()
{
goto a;
}
a :;
}
b :;
while (1 == 1)
{
goto b;
loop ()
{
goto a;
}
a :;
}
b :;
The application of break in
CODE:
for (int n=0; n <5; n ++)
{
while (1 == 1)
{
break;
loop ()
{
break;
}
}
if (n == 2) break;
}
for (int n=0; n <5; n ++)
{
while (1 == 1)
{
break;
loop ()
{
break;
}
}
if (n == 2) break;
}
is tantamount to
CODE:
for (int n=0; n <5; n ++)
{
while (1 == 1)
{
goto b;
loop ()
{
goto a;
}
a :;
}
b :;
if (n == 2) goto c;
}
c :;
for (int n=0; n <5; n ++)
{
while (1 == 1)
{
goto b;
loop ()
{
goto a;
}
a :;
}
b :;
if (n == 2) goto c;
}
c :;