Sujet : Re: else ladders practice
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.cDate : 31. Oct 2024, 15:17:44
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <773e1aab372664d48800c94d931f294c2cfe720d@i2pn2.org>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
Richard Harnden wrote:
On 31/10/2024 12:11, fir wrote:
somethins i got such pices of code like
>
if(n==1) {/*something/}
if(n==2) {/*something/}
if(n==3) {/*something/}
if(n==4) {/*something/}
if(n==5) {/*something/}
>
technically i would need to add elses - but the question is if to do
that
>
Why not ...
>
switch (n)
{
case 1:
/* something */
break;
>
case 2:
/* etc ... */
>
default:
/* something else */
}
>
... ?
>
>
switch is literally flawed construction - (i was even writing or at
kleast thinking why, last time but sadli i literrally forgot my
arguments, would need to find that notes)
>
so i forgot why but i forgiot that it is flawed - i mean the form of
this c switch has sme error
>
>
>
>
>
>
ok i found it was here in a thread freeform switch case
i was noted that swich shoudl look like
switch(a);
case(1) {}
case(2) {}
case(3) {}
case(4) {}
case(5) {}
i mean thuis enclosing brackets are wrong..and makes thic construction hard to understand
here its cleat case simply work witch last swich (though this could be understood in few ways, liek it could be last in runtime or last in top-down listing etc
also betetr word for switch is probably "select"
also case probably culd have 2 forms
case(1) { }
case(2) { }
dont needs break as its exclosive execution
case 1:
case 2:
case 3:
could eventually work like goto and fall through
(though im not sure what is needed and what not)
overally the one thing is rather sure those enclosing {} are wrong
and that swich case clausule in generall could have many variations
not only one
(this fallthru one probably should have name closer to goto