🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #797

Re: Taming The Switch-Statement

#797
From: fir
Date: Mon, 26 Oct 2026 16:37
120 lines
5106 bytes
bartc pisze:
> On 26/10/2026 16:03, fir wrote:
>> bartc pisze:
>>> On 26/10/2026 12:20, fir wrote:
>>>> bartc pisze:
>>>>> On 26/10/2026 12:07, fir wrote:
>>>>>> fir pisze:
>>>>>>> if {} or if {} or if {} else {}
>>>>>>
>>>>>>
>>>>>> this form in fact is not bad, it simply showst two things
>>>>>>
>>>>>> 1) you may use or outside the if clause (if this () can be named 
>>>>>> clause)
>>>>>>
>>>>>> 2) else in fact work on logical group but ias sole if is alos a 
>>>>>> case of logical group so else work on it sole in special case
>>>>>>
>>>>>> otherwiste thse keywords here if or and else are quite 'legit'
>>>>>>
>>>>>>
>>>>>>
>>>>>> if () {}
>>>>>> or if () {}
>>>>>> or if() {}
>>>>>> else {}
>>>>>>
>>>>>>
>>>>>> seems quite legit and it seem to ba a switch
>>>>> Excellent. A great thing about this is, this can also be legal C, 
>>>>> that works now, if you just precede with this:
>>>>>
>>>>>    #define or else
>>>>>
>>>> this wouldnt work imo as far as im aware becouse this last else dont 
>>>> work on "group'
>>>
>>> This works fine:
>>>
>>>      #define or else
>>>
>>>      for (int i=0; i<=5; ++i)
>>>          if    (i==1) {puts("One");}
>>>          or if (i==2) {puts("Two");}
>>>          or if (i==3) {puts("Three");}
>>>          else         {puts("Other");}
>>>
>>> Output is:
>>>
>>>    Other
>>>    One
>>>    Two
>>>    Three
>>>    Other
>>>    Other
>>>
>>> The point is you eventually came up with syntax that is actually just 
>>> C but using 'or' in place of 'else'.
>>>
>>>> the last else is what i name "otherwise" (its else in all other case"
>>> You seem to have named it 'else' in your example. In any case it 
>>> would just be a slightly different choice of keyword; it buys you 
>>> very little.
>>>
>> maybe try with like
>>
>> case x%2==0 //2 4 6 8 10 12
>> case x%3==0 //3 6 9 12
> 
> No, cases '6' and '12' are also true for x%2==0. Unless you want these 
> to be non-exclusive?
> 
>> default  // 1 5 7 11 13
>>
>>
>> the default should run if none of above cases catch (as i remember coz 
>> i dont use switch) and  thse cases  should catch each time
> 
> OK. C doesn't have a direct syntax for this. But it does have if-else 
> chains for precisely this job. What is the problem with that? You can 
> write it like this if you like:
> 
>     if (0)
>     else if (x%2==0) {}
>     else if (x%3==0) {}

you want it the above to pront "divides by 2" "divides by 3" for 6 and 
12 "divides by 2" for 4 8 and 'divided by 3" for 2 9 in case it not 
divides by 2 or 3 pronts "no divides "

this above will not work for 6 for example as it only will prit "divides 
by 2"

> 
> if you want consistency. There's no point in creating a slightly 
> different syntax for the same thing.
> 
>> im maybe talkong about some more general switch here
> 
> What does 'switch' mean to you? It seems that every day it is something 
> with more and more capabilities and it gets more ambiguous. At some 
> point it will its own AI to divine your intentions.
> 
>   but this general
>> (abstract) it is more important then normal one - as thsi general 
>> covers various possible cases
>>
>> using if or you can implement i it
>>
>>     if(x%2==0) {}
>> or if(x%3==0) {}
>> else {}
>>
>> without or (or something analogic) as i understand if im not wrong you 
>> cant
> You seem fixated on that 'or'. Either use 'else', or create 'or' as an 
> alias as I suggested.
> 
> 
Technical Details
Message-ID: <11bnvl2$opb9$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me> <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me> <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me> <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 26 Oct 2026 17:37:53 +0100
Organization: A noiseless patient Spider
Lines: 120
Message-ID: <11bnvl2$opb9$1@dont-email.me>
References: <119qf6l$2rmg3$1@dont-email.me> <11ba02r$3pl5h$1@dont-email.me>
 <11bnfpm$i84l$1@dont-email.me> <11bng23$iblc$1@dont-email.me>
 <11bngj1$ifj5$1@dont-email.me> <11bnnbg$l7i1$1@dont-email.me>
 <11bntk0$nsbo$1@dont-email.me> <11bnvbq$olbj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 26 Oct 2026 16:37:55 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="812393"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+lVnNPoMVRmTBX17LZsxr8Ui+pNBdLfUA="; posting-host="524fd3863234ce524468884467e01d13"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:F/ZnNjozYMrXgHr/cgNovs5vrzs= sha256:3/YUpQvJIulgOYSR30g1t9O39nAr4XaDR+lxvwv98r8=
	sha1:eIdXazMsPjyltTP/1qt/hFrF7+I= sha256:22eMHJ/s5WTKvPSps4o1lI1Dhu3UXakYsnZi6KdM6DQ=
In-Reply-To: <11bnvbq$olbj$1@dont-email.me>