Trouble converting while loops to for and do loop

Hi 2 everyone,
I have been working on this for some time now and have been stuck in the same spot. I have figured out how to get the answer I wanted with 2 while loops but now I'm trying to convert them to a for and do loop. If any one could explain it to me I would really appreciate it. These are the while loops I would like to try to convert to the for and do loops.
Last edited on
If a for loop has the form
1
2
3
for ( a ; b ; c ) {
  d;
}

Then a while loop is just
1
2
3
while ( b ) {
  d;
}

So you might start with
1
2
3
for ( ; (inValue / quotient) > RADIX ; ) {
    quotient *= RADIX;
}

which can be further simplified to
1
2
3
for ( ; (inValue / quotient) > RADIX ; quotient *= RADIX ) {
    ;
}


A while loop into a do loop is harder, because a while loop can execute 0 times, whereas a do loop must execute at least once.
So you end up with a messy
1
2
3
do {
  if ( !quotient ) break;
} while ( true )


Thank you very much for the detailed and easy to understand explanation!
@cpluspython - please don't edit the original post so that future answers are out of context. It's not good etiquette.
Topic archived. No new replies allowed.