Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > break outside a loop and a switch

Reply
Thread Tools

break outside a loop and a switch

 
 
Peter Nilsson
Guest
Posts: n/a
 
      01-30-2006
serrand wrote:
> Could someone tell me a beautiful way to exit from a switch and a loop in one
> statement ...


Yes...

> without using a goto...


What have you got against goto?

--
Peter

 
Reply With Quote
 
 
 
 
clayne
Guest
Posts: n/a
 
      01-30-2006
Nelu wrote:
> a while loop is executed as long as the condition is true.
> I do not consider while(1) an elegant way to program.
> It may make your code faster and that's fine if that's what you
> want, but I would use a variable that can change to false
> when you want it to.


It's not about elegant - it's about get it done.

Anyways, why not state what you wanted to state?

while (res) { res = blah(); }

 
Reply With Quote
 
 
 
 
Nelu
Guest
Posts: n/a
 
      01-30-2006
clayne wrote:
> Nelu wrote:
>> a while loop is executed as long as the condition is true.
>> I do not consider while(1) an elegant way to program.
>> It may make your code faster and that's fine if that's what you
>> want, but I would use a variable that can change to false
>> when you want it to.

>
> It's not about elegant - it's about get it done.
>

Yes, it is about getting it done but I replied to the elegant
way question.

> Anyways, why not state what you wanted to state?
>
> while (res) { res = blah(); }

I guess it would've been easier to do just that. I don't know
why I didn't do it.


--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
 
Reply With Quote
 
Neil
Guest
Posts: n/a
 
      01-31-2006
How about:

int res = 0 ;

while (!res)
{
res = 0;
if ((i = msgrcv (msqid, &rq_resa, SZ_MsgSrcResa, pid(), 0) == -1)
{
aff_erreurs ("msgrcv", "Error when recieving message : %d",
errno);
continue;
}
if (strcasecmp (rq_resa.mess,"admin"))
printf ("Admin d'ont manage bad formatted messages...\n");
else
switch (rq_resa.rep)
{
case 'q':
res = working_q();
manage_error (res);
break;
case 'f':
res = working_f();
manage_error (res);
break;
default:
printf ("This function is not yet implemented...\n");
}
}
 
Reply With Quote
 
clayne
Guest
Posts: n/a
 
      02-01-2006
Neil wrote:
> int res = 0 ;
>
> while (!res)
> {
> res = 0;


What?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
`if (!p ? i++ : 0) break;' == `if (!p){ i++; break;}' ? lovecreatesbea...@gmail.com C Programming 12 04-14-2008 07:59 AM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
How to break a while loop inside a switch statement? howachen@gmail.com Java 16 07-11-2006 10:23 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM



Advertisments