Article View: comp.lang.c
Article #1196Re: Taming The Switch-Statement
From: Rosario19
Date: Sat, 31 Oct 2026 09:54
Date: Sat, 31 Oct 2026 09:54
56 lines
3248 bytes
3248 bytes
On Thu, 29 Oct 2026 12:31:48 +0100, fir wrote:
>Rosario19 pisze:
>> On Mon, 26 Oct 2026 18:06:51 +0100, fir wrote:
>>> bartc pisze:
>>>> On 26/10/2026 16:45, fir wrote:
>>>>> bartc pisze:
>>>>>>> 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.
>>> 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
>>> 6 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
>>> 12 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
>>> 18 divides by 3
>>> 19 no divides (by 2 or 3)
>
> if(x%2==0) printf("%d divides by 2\n",x); else goto mod2false;
> if(x%3==0) printf("%d divides by 3\n",x); else goto mod2true3false;
> goto out;
>mod2true3false:
> goto out;
>
>mod2false:
> if(x%3==0) printf("%d divides by 3\n",x); else mod2false3false;
> goto out;
>mod2false3false:
> printf("%d no divides (by both 3 and 2)\n",x);
>out:
>
>but its also bad - you repeat the mod 3 calculation in 2 branches
>
>on assembly level it seem you also need to hold a state but its inner
>state can be uin register you dont need name it etc
if(x%2==0) printf("%d divides by 2\n",x); else goto mod2false;
is wrong because before the else has to be executed
if(x%3==0) printf("%d divides by 3\n",x);
Technical Details
Message-ID:
<ghebel1qa19e9m9222783ebg6ra9k376oa@4ax.com>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-mailReferences:
<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> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <tft5elp1q2ns7rhfp3rod862ks5ip3p0ms@4ax.com> <11bvar6$39oar$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: Rosario19 <Ros@invalid.invalid> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Sat, 31 Oct 2026 10:54:13 +0100 Organization: A noiseless patient Spider Lines: 56 Message-ID: <ghebel1qa19e9m9222783ebg6ra9k376oa@4ax.com> 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> <11bo02r$otr5$1@dont-email.me> <11bo0ul$pbso$1@dont-email.me> <11bo1bc$phlr$1@dont-email.me> <tft5elp1q2ns7rhfp3rod862ks5ip3p0ms@4ax.com> <11bvar6$39oar$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Sat, 31 Oct 2026 09:46:16 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1056633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18afxknZhxifAH1LCjU3zBzcANBmyYab9M="; posting-host="16b6d0dc3bfca910e87f2c3e3067af6e" Cancel-Lock: sha1:R9QfDqZVI729V5Euwy2hcJHn7eo= sha256:RTu3f02vpkbnF/2goIKWz8OomVJ6uf0vvPPRqzZWSPg= sha1:VHO0B0hKUeZdd4SeHhYAxTw2eAc= sha256:guWngfMVRJDVzKCEWOV/ORNRrRDQNWcnCM1BhJkBXbc= X-Newsreader: Forte Free Agent 1.93/32.576 English (American)