José de Paula wrote:
> On 2004-01-30, nrk <> wrote:
>> José de Paula wrote:
>>
>>> Is getopt() and its companions, commonly found in GNU libc and other
>>> Unices libc, part of the C standard?
>>>
>>
>> No, but it is part of POSIX (which is OT in this newsgroup).
>>
>
>>><snip goto meaning "continue">
>
>>
>> What you really want is not break out of the while, but continue (since
>> you say goto start which is the start of the while loop). A continue
>> will work just fine as it doesnt have special meaning inside the switch.
>
> Yes, what I want is continue, thanks. So in this case I could just use
> continue?
Yes.
> It feels counter-intuitive, because I'm used to the fact that,
> syntactically (sp?), break and continue are the same thing, even though
> continue doesn't have any meaning inside switch blocks.
>
Well, break and continue are not the same thing at all semantically. One
takes you out of the loop while the other just skips the rest of the code
for the current iteration of the loop. I agree with you on the
counter-intuitive part, as I also see break/continue as a pair that often
go together. The problem probably stems from a lazy compiler writer in the
early days who decided to re-use break for a somewhat similar purpose
instead of introducing a new keyword for use inside switch statements
See Chris Torek's excellent recent post on switch statements for a peek
under the hood:
<>
-nrk.
>>
>> If you really want to break out of the while loop, no real easy and
>> elegant
>> way. You'll have to maintain a possibly useless separate flag and
>> unnecessarily check it as part of your while condition. A goto might be
>> cleaner and efficient. Don't be dogmatic in rejecting programming
>> constructs.
>
> Yeah, sure. In this case I don't see the goto as a big problem, because
> the label is near the goto, and it's clear what the code does. I rather
> prefer it than using the extra variable.
>
--
Remove devnull for email