Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > one VS another ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 958 of 1009
Post > Topic >>

one VS another (while)

by Santa Claus <santa@[EMAIL PROTECTED] > Feb 25, 2008 at 05:54 PM

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.
 




 8 Posts in Topic:
one VS another (while)
Santa Claus <santa@[EM  2008-02-25 17:54:50 
Re: one VS another (while)
Sherman Pendley <spamt  2008-02-25 21:59:28 
Re: one VS another (while)
Greg Parker <gparker@[  2008-02-25 20:22:00 
Re: one VS another (while)
Greg Parker <gparker@[  2008-02-25 20:45:57 
Re: one VS another (while)
Gregory Weston <uce@[E  2008-02-26 08:55:53 
Re: one VS another (while)
Greg Parker <gparker@[  2008-02-26 15:30:08 
Re: one VS another (while)
Gregory Weston <uce@[E  2008-02-26 08:53:17 
Re: one VS another (while)
David Phillip Oster <o  2008-03-03 03:34:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 23:59:08 CDT 2008.