Deutsch English Français Italiano |
<slrnvl31e7.u69.dan@djph.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Dan Purgert <dan@djph.net> Newsgroups: comp.lang.c Subject: Re: else ladders practice Date: Thu, 5 Dec 2024 10:51:51 -0000 (UTC) Organization: A noiseless patient Spider Lines: 60 Message-ID: <slrnvl31e7.u69.dan@djph.net> References: <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> <slrnvi746p.fkp.dan@djph.net> <else-20241116103316@ram.dialup.fu-berlin.de> <slrnvjrll7.fkp.dan@djph.net> <rgfmkjh1549m886b3labjimj73mdce4g1s@4ax.com> Injection-Date: Thu, 05 Dec 2024 11:51:52 +0100 (CET) Injection-Info: dont-email.me; posting-host="815003557958bafbbbe5dd20c8e0f167"; logging-data="1645030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xVZ3hzXMbUUxoqEoyqD+HbDH/P0KHT64=" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:jCiGXqVDJzu1CNC/HYZCotr6Z2U= Bytes: 2820 On 2024-11-30, Rosario19 wrote: > On Wed, 20 Nov 2024 12:31:35 -0000 (UTC), Dan Purgert wrote: > >>On 2024-11-16, Stefan Ram wrote: >>> Dan Purgert <dan@djph.net> wrote or quoted: >>>>if (n==0) { printf ("n: %u\n",n); n++;} >>>>if (n==1) { printf ("n: %u\n",n); n++;} >>>>if (n==2) { printf ("n: %u\n",n); n++;} >>>>if (n==3) { printf ("n: %u\n",n); n++;} >>>>if (n==4) { printf ("n: %u\n",n); n++;} >>>>printf ("all if completed, n=%u\n",n); > > above should be equivalent to this > > for(;n>=0&&n<5;++n) printf ("n: %u\n",n); > printf ("all if completed, n=%u\n",n); Sure, but fir's original posting in MID <3deb64c5b0ee344acd9fbaea1002baf7302c1e8f@i2pn2.org> was a contrived sequence to the effect of if (n==0) { //do something } if (n==1) { //do something } if (n==2) { //do something } if (n==3) { //do something } if (n==4) { //do something } So, I merely took the contrived sequence, and made "do something" trip each condition. Stefan's example from a few posts back is better: >>> Well, it's a blue moon when someone nails it. Most of them fall >>> for my little gotcha hook, line, and sinker. >>> >>> #include <stdio.h> >>> >>> const char * english( int const n ) >>> { const char * result; >>> if( n == 0 )result = "zero"; >>> if( n == 1 )result = "one"; >>> if( n == 2 )result = "two"; >>> if( n == 3 )result = "three"; >>> else result = "four"; >>> return result; } >>> >>> void print_english( int const n ) >>> { printf( "%s\n", english( n )); } >>> >>> int main( void ) >>> { print_english( 0 ); >>> print_english( 1 ); >>> print_english( 2 ); >>> print_english( 3 ); >>> print_english( 4 ); } -- |_|O|_| |_|_|O| Github: https://github.com/dpurgert |O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1 E067 6D65 70E5 4CE7 2860