[try Beta version]
Not logged in

 
is it correct to use continue too skip some loop conditions?

Feb 8, 2023 at 9:43am
or there other way
Feb 8, 2023 at 9:54am
yes. The other way is to reverse the continue condition and use the if-body for the code to be executed. Can get messy.
Last edited on Feb 8, 2023 at 12:36pm
Feb 8, 2023 at 11:41am
With example:
1
2
3
4
5
6
for/while/do ...
{
   A;
   if ( condB ) continue;
   B;
}


1
2
3
4
5
6
7
for/while/do ...
{
   A;
   if ( not condB ) {
      B;
   }
}

In both cases the statement B is evaluated only when the condition condB is false.
Last edited on Feb 8, 2023 at 11:41am
Topic archived. No new replies allowed.