Tech Support Guy banner
Status
Not open for further replies.
1 - 4 of 4 Posts

·
Registered
Joined
·
41 Posts
Discussion Starter · #1 ·
I have been trying to figure out the answer to this problem for hours..

Describe the process you would use to replace a do...while loop with an equivalent while loop. What problem occurs when you try to replace a while loop with an equivalent do ...while loop? Suppose you have been told that you must remove a while loop and replace it with a do... while. What additional control statement would you need to use and how would you use it to ensure that the resulting program behaves exactly as the original?
 

·
Retired Trusted Advisor
Joined
·
7,154 Posts
I believe with a do...while loop, the loop condition is tested after the loop has executed at least once. With a while loop, the loop condition will be tested before the loop executes.

If I were to replace a do...while loop with a while loop, I would do something like this:

(pseudo-code)

do {
//loop code goes here
if done condition is met then
done = True;
} while(!done)

done = False;
while(!done) {
//Do the loop code
if done condition is met then
done = True;
}

***********************

If I were to replace a while loop with a do...while loop, I would do this:

while(!done) { // done condition could have already been met so loop would not run
//Loop code
if done condition is met then
done = True;
}

if (!done) {
do {
// Loop code goes here
if done condition is met then
done = True;
} while(!done)
}

Now, I'll go look this up to see if I'm even close. :D

Peace...
 

·
Registered
Joined
·
106 Posts
Rhino, you really should work on your homework on your own. I don't mind helping, but the number of posts I'm seeing sounds like you're looking for the easy way out. Perhaps you should seek help from your teacher to help? Others DOING your homework will not help you.
 

·
Retired Trusted Advisor
Joined
·
7,154 Posts
Rhino, you really should work on your homework on your own. I don't mind helping, but the number of posts I'm seeing sounds like you're looking for the easy way out. Perhaps you should seek help from your teacher to help? Others DOING your homework will not help you.
I agree. I'm sorry I posted what I did above. :(

Peace...
 
1 - 4 of 4 Posts
Status
Not open for further replies.
Top