my break; is working only on outside loop [i], but inside loop [h] runs 5 times everytime, if i put break;break; - nothing changes at all O_oCode:
for (int i = 0; i < 10; i++)
{
for (int h = 0; h < 5; h++)
{
break;
{
}
how do i break inside loop?
Printable View
my break; is working only on outside loop [i], but inside loop [h] runs 5 times everytime, if i put break;break; - nothing changes at all O_oCode:
for (int i = 0; i < 10; i++)
{
for (int h = 0; h < 5; h++)
{
break;
{
}
how do i break inside loop?
You can use a bool flag.
Code:bool breakAll = false;
for (int i = 0; i < 10 && !breakAll; i++)
{
for (int h = 0; h < 5 && !breakAll; h++)
{
breakAll = true;
}
}
actually my break; is continue; i want to skip to next, i just used break; cuz continue; continued on the same check forever
Then why don't you say so on the first place? If you want to buy apples you don't ask for peaches.
Code:for (int i = 0; i < 10; i++)
{
bool skipTheRest = false;
for (int h = 0; h < 5; h++)
{
if(...)
{
skipTheRest = true;
break; // from the inner if
}
}
if(skipTheRest)
continue;
// the rest
}
code above freezes my program
found a solution, break inside 2nd loop was working for 2nd loop, if 2nd loop's step had no break it continued forever
i added a bool condition for 2nd loop conditions, break for every not met if condition in 2nd loop, and check for bool to do else action in 1st loop after 2nd, but without any break in 2nd loop and it works like it should now
That might also go like this:
Code:
inline bool interior()
{
for (int h = 0; h < 5; h++)
{
if(...)
{
return false;
}
}
return true;
}
for (int i = 0; i < 10; i++)
{
if( ! interior() ) continue;
// the rest
}
or that could be
for (int i = 0; i < 10; i++)
{
if( interior() )
{
// the rest
}
}
If common data is used in the interior and the i loop, these could be the member of a class, which holds the common data.