🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #807

Re: Taming The Switch-Statement

#807
From: fir
Date: Mon, 26 Oct 2026 19:03
135 lines
4678 bytes
Janis Papanagnou pisze:
> On 2026-10-26 17:42, bartc wrote:
>> On 26/10/2026 16:37, fir wrote:
>>> 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 {}
> [...]
>>>>>>>>> if () {}
>>>>>>>>> or if () {}
>>>>>>>>> or if() {}
>>>>>>>>> else {}
> [...]
>>>>>>      #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");}
> [...]
>>>>> case x%2==0 //2 4 6 8 10 12
>>>>> case x%3==0 //3 6 9 12
>>>>> default  // 1 5 7 11 13
> [...]
>>>>     if (0)
>>>>     else if (x%2==0) {}
>>>>     else if (x%3==0) {}
> [...]
>>    if (x%2==0) {}
>>    if (x%3==0) {}
>>
>> Here it is clear they are non-exclusive.
>>
>> You're also in luck: this is exactly how C works now!
> 
> I'm not sure what fir actually wants; I cannot decipher his writings
> quoted by you. But, given that he not yet seems satisfied with your
> replies and suggestions, could it, by any chance, be that what he
> wants is some non-deterministic construct like Dijkstra's Guards?
> 
> I.e., that with two guards 'x%2==0' and 'x%3==0' and an input of "6"
> only _one_ of the two gets _arbitrarily_ triggered?
> 
> (Otherwise his post appears quite pointless to me.)
> 
> Janis
> 


i quite defined the problem see the simple program


for(int i=0; i<20; i++)
{
	printf("\n %d,i);

	if(x%2==0)
            printf("\n divides by 2");
        or if(x%3==0)
            printf("\n divides by 3");
        else
           printf("\n no divides (by 2 or 3)");

}

keyword or resloves problem here the problem is if you add or the else 
works on grpup of previous ifs

    here  in cases

   0 or 0 else {}
   1 or 0 else {}
   0 or 1 else {}
   1 or 1 else {}


else works on fales so here olse works like default
in switch only on all zeros


write such above program without or so it giver the desired result


  1
  no divides (by 2 or 3)
  2
  divides by 2
  3
  divides by 3
  4
  divides by 2
  5
  no divides (by 2 or 3)
  6
  divides by 2
  divides by 3
  7
  no divides (by 2 or 3)
  8
  divides by 2
  9
  divides by 3
  10
  divides by 2
  11
  no divides (by 2 or 3)
  12
  divides by 2
  divides by 3
  13
  no divides (by 2 or 3)
  14
  divides by 2
  15
  divides by 3
  16
  divides by 2
  17
  no divides (by 2 or 3)
  18
  divides by 2
  divides by 3
  19
  no divides (by 2 or 3)

my thoughts are general as o abstract switch concept and its a bit 
multidimensional ;c maybe but specifically
ut shows that if and elses not cover all logical cases when
if you add such or and and (or some different analogies) those cases
would be covered
Technical Details
Message-ID: <11bo85p$sga7$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> <11bnvl2$opb9$1@dont-email.me> <11bnvug$otdl$1@dont-email.me> <11bo6pv$36mvl$3@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 20:03:20 +0100
Organization: A noiseless patient Spider
Lines: 135
Message-ID: <11bo85p$sga7$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>
 <11bnvl2$opb9$1@dont-email.me> <11bnvug$otdl$1@dont-email.me>
 <11bo6pv$36mvl$3@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 19:03:21 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="934215"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19Q0lF+3drim3UegyKq+zga5QcgjU7ewVg="; 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:f11qRf5voYo+Tqp62y8Xr7wHhyI= sha256:Jn+MWDuM0l5iXTvB4Avqrm+ruzbcjSuYgvf/K61pFy0=
	sha1:VSh3nn9WKYMb7pbE34SRRYnfoAE= sha256:1i9Z3d8h1ampJc9Q7g/THJxPY/lUBe+ZKG+GRDbfC8g=
In-Reply-To: <11bo6pv$36mvl$3@dont-email.me>