The syntax for this control structure is shown below.
do body while (condition)
The difference between a while loop and a do-while loop is that the do-while loop always executes the body at least once, whereas the while loop may not execute it at all.
do
{
x = x+1;
y = y*2;
} while(x < 10);
If you don't put the values on the screen you have no way of knowing what is happening.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
float x = 0;
float y;
task main()
{
do
{
y = x;
}
until(1);
}
I think this is the result of macro expansion. "until(x)" is defined as "while(!(x))". So at the end the statement is "while (!(1))". A real c compiler will make a "false" out of this but may be "nxc" is confused by that construction.
Give "while(0)" a try and tell us the result.
Bye Marvin
- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
Which firmware do you use? The stock LEGO one or the extended firmware? If you are using the stock one did you setup the nxc compiler like that? If you are using the extended firmware you should upgrade to the one packaged in the bricxcc package. I know that John optimized and corrected floating point things. They may not work always correctly in older firmware versions.
Bye Marvin
- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
mrblp wrote:
I think this is the result of macro expansion. "until(x)" is defined as "while(!(x))". So at the end the statement is "while (!(1))". A real c compiler will make a "false" out of this but may be "nxc" is confused by that construction.
Give "while(0)" a try and tell us the result.
I'm not sure.
It's looks fine if replace float variable with int, still using "until".
IMO it's a good advice to ALWAYS check "enhanced firmware" if you're working with NXC (and of course having it already uploaded to the NXT).
Another hint according to my experiences:
better always drop "until" if possible and ever use "while" if possible.
"until" often and easily leads to logical misunderstandings, misinterpretations, and misconstructions;
additionally, "until" is no legal standard C keyword but only "while"
- regardless if any C preprocessor always allows you to
#define until(x) while(!x)
There's definitely something going wrong - possibly a floating point type opcode incompatibility of some kind. Can you try with different optimization levels to see if it is an optimizer bug or a code generator bug? My guess is it is in the optimizer. It may be something that works with the enhanced firmware but not the standard firmware but I tried to avoid those sorts of issues as much as possible, i.e., code generation that hangs the standard firmware but works with enhanced vs code that doesn't compile for the standard firmware but does with the enhanced firmware. The latter is fine but I have tried to avoid the former.
Also, can you use the variables in the loop? They are being (partially) optimized out and that may lead to the bug you are seeing. Is there a "real code" case where this is hanging the brick or can you only replicate it in a trivial loop like you posted? For example, add code to write X and Y to the LCD using NumOut or something along those lines.
I would encourage you to use the "automatic firmware" option if that is not already checked. That lets you check 2.0 and Enhanced but then it will automatically switch to standard if that is what you have installed on your NXT.