This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Strange problem with loop

Hi.

Ive been programing for nearly five months now so I am not a noob but I cannot understand this;

for ( variable = 1 ; variable < 100 ; variable += 1 )
{
  // some code

  if ( foofar )
    continue ;
  else
    sumfunc () ;
}

<endpre>

if i continue does the variable get added?


Parents
  • The continue will jump to the closing brace of the for loop, so it will side-step any work you have inside the for body. But the expr3 (your increment) will be performed before expr2 is tested again to decide if a further iteration should be made.

    If you don't have the language standard (paragraph 6.8.6.2) you can test this yourself. Remember that you can use the free MinGW Win32 compiler to write test applications on the PC. As long as you take care of the size of variables, you can debug a lot of algorithms on the PC before moving the code to the 8051 target.

Reply
  • The continue will jump to the closing brace of the for loop, so it will side-step any work you have inside the for body. But the expr3 (your increment) will be performed before expr2 is tested again to decide if a further iteration should be made.

    If you don't have the language standard (paragraph 6.8.6.2) you can test this yourself. Remember that you can use the free MinGW Win32 compiler to write test applications on the PC. As long as you take care of the size of variables, you can debug a lot of algorithms on the PC before moving the code to the 8051 target.

Children