Jump to content
  • Advertisement
Sign in to follow this  
Cibressus

i broke while

This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
If you post your code, then we can tell what you are doing wrong.

Maybe you have a semicolon after you while statement by mistake? Only the do...while version should be terminated by a semicolon.

I can't make a guess other than that, without seeing any code.

Share this post


Link to post
Share on other sites
no, no matter what i put

for example

while(1)
{
printf("this");
}

simply does not loop, i've had another programer check it to make sure i'm not going insane.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cibressus
for some reason, my while loop no longer works, no matter what code i do, but dowhile still works. any insight?

We need more information, preferably source code, to be able to help you.
There's not much to say about do { } while and while except that they perform two different functions.

edit: 23 seconds too late =)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Cibressus, are you serious?

Share this post


Link to post
Share on other sites
Quote:
Original post by Cibressus
no, no matter what i put

for example

while(1)
{
printf("this");
}

simply does not loop, i've had another programer check it to make sure i'm not going insane.


So if you replace that code with

do
{
printf("this");
}while(1);




without changing anything else in the program, it loops?

I'm pretty sure you have something else wrong a few lines above the loop.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cibressus
no, no matter what i put

for example

while(1)
{
printf("this");
}

simply does not loop, i've had another programer check it to make sure i'm not going insane.

Exactly what happens? Does the program get stuck without generating any output, do you get a compiler error, does it print the first line and then exit or something else entirely?
That piece of test code might not generate any output because of c's line buffering. Try adding a newline.
Have you tried writing a separate test application consisting only of an infinite loop?

Share this post


Link to post
Share on other sites
Taking the "while (1) doesn't work case" as the basis for investigation:

1) What does it do when you single step it? I suspect infinity...

2) Try putting some non-important code after the while loop, put the cursor on that code and then do a "run to cursor" - is it ever getting there?

3) Bear in mind that the stdio streams have buffers and buffer limits - although "this" may have stopped appearing in your output/console window, it doesn't mean the loop itself has stopped! Try flushing the stream and adjusting the buffer.

4) Look at the assembly listing, see if it makes sense - every compiler I've worked with hasn't got anything as trivial as "while (1)" wrong in any way!!!

5) If the original cause for this post was a while loop involving floating point values, then what epsilon are you using? (if the answer to that is "epsilon, what?", then that's your problem...)

6) Somebody doing something stupid like #define'ing "1" or "while" would cause funnies (have only ever had to do anything so extreme in very rare debugging scenarios though!)

7) Is there a multi threaded element to this? if so, what synchronisation objects are you using, and how? A while loop checking a flag which is owned by another thread can very easily mis-generate code (often as bad as self:jmp self) without warning. If this is the case, try declaring shared variables as "volatile", and ideally use proper/safe synchronisation objects.

Share this post


Link to post
Share on other sites
Quote:
Original post by felisandria
Is it possible to overload "while"? *ponder*

-fel


Yes(ish): #define...

I've had to do it to help trace a program lock-up that only occurred in release builds. Someone on the team favoured while loops which compared float values for equality (GRRR!!) - the iteration count of the suspect while loops shouldn't have been more than 5 or 6, so I #define'd a version of while that was cause a breakpoint if it went over 1000 iterations and was #undef'd outside of the file under investigation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!