i have a simple question. what's the difference between these two ways
of handling while?
1)
while (condition)
{
do something
change condition if needed
}
2)
do
{
do something
change condition if needed
}
while (condition)
personally, i prefer version 1 but that means that condition would have
to be preset before entering into the loop and there's a possibility of
it not going into the loop based on the condition when it enters the
loop. the second one forces at least one loop execute before even
testing the condition which may be detrimental to the program.
i'm asking this because i see the following in Apple's headers.
#define _NSAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5) \
do { \
if (!(condition)) { \
[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd
object:self file:[NSString stringWithCString:__FILE__] \
lineNumber:__LINE__ description:(desc), (arg1), (arg2), (arg3),
(arg4), (arg5)]; \
} \
} while(0)
another thing i'd like to know is why do a while false or while true?
shouldn't you actually TEST for something instead of testing a constant
and then breaking out if an inside test results in something?
this is what i've seen once (from a teacher no less). shouldn't it be
"while condition" instead of "while true"?
while (true)
{
do something
if (some condition)
{
break;
}
}
ok ok, enough of me ranting on and on. i'll get off my soapbox but i
WOULD like to know just for curiosity's sake.


|