Deutsch English Français Italiano |
<vttig0$32ksb$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Fri, 18 Apr 2025 15:01:50 +0200 Organization: A noiseless patient Spider Lines: 58 Message-ID: <vttig0$32ksb$1@dont-email.me> References: <vspbjh$8dvd$1@dont-email.me> <vtc7mp$2q5hr$1@dont-email.me> <vtcqf6$3j95s$1@dont-email.me> <vtdh4q$b3kt$1@dont-email.me> <vtf7fe$1qtpg$1@dont-email.me> <vtgfuf$31ug1$1@dont-email.me> <20250413072027.219@kylheku.com> <vtgpce$39229$1@dont-email.me> <vti2ki$g23v$1@dont-email.me> <vtin99$vu24$1@dont-email.me> <vtiuf0$18au8$1@dont-email.me> <vtj97r$1i3v3$1@dont-email.me> <vtl166$36p6b$1@dont-email.me> <vtlcg0$3f46a$2@dont-email.me> <20250415053852.166@kylheku.com> <vtm4ae$6d5j$1@dont-email.me> <H7yLP.2056536$OrR5.1414451@fx18.iad> <vtmgj8$g81k$1@dont-email.me> <vtnfjj$1gk91$1@dont-email.me> <vto4fu$23kmr$1@dont-email.me> <20250416150837.00004587@yahoo.com> <vtof09$2db8v$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 18 Apr 2025 15:01:52 +0200 (CEST) Injection-Info: dont-email.me; posting-host="58e70a2ceb8cc8902b7a0511d788138d"; logging-data="3232651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180nLbu2rBd8xVmztvf1BaW" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:SE/jre2HrcaBmpmWMZrZ68r/rYU= X-Enigmail-Draft-Status: N1110 In-Reply-To: <vtof09$2db8v$1@dont-email.me> Bytes: 3752 On 16.04.2025 16:31, bart wrote: > On 16/04/2025 13:08, Michael S wrote: >> [...] > > When languages used to be 1-based, it was easy. Then 0-based came along, > and typically iteration changed from 1..N inclusive, to 0..N-1 inclusive. You should be aware that [simple] linear iterations are conceptually coupled to arrays. The choice of 0-based arrays and thus iterations is "useful" for compiler creators of such languages. They allow without overhead and skill for optimization an efficient array access. > [...] >> Oh, now you could interpret a written above as statement of superiority >> of C syntax. So, no, it is not. Those are *minor* points. > > Here's some C code to print the elements of an array: > > static char* table[] = {"one", "two", "three", "four", "five"}; > > for (int i=0; i<sizeof(table)/sizeof(table[0]); ++i) > printf("%d %s\n", i, table[i]); (This all exposes quite clearly the low-level characteristics of "C".) > And here is how I'd write it using the 'minor' advantages of my syntax: > > static []ichar table = ("one", "two", "three", "four", "five") > > for i, s in table do > println i, s > end > > To me, the differences in that for-loop are like chalk and cheese. Sure, many language support newer syntaxes for such things. Even older languages do such abstractions; e.g. Awk[*] split ("one two three four five", table) for (i in table) print i, table[i] (One of many things I like in this very small but powerful language.) > > (Note that the latter is 1-based, but it is not apparent in the code; > the outputs are numbered 1 to 5. The C is zero-based, and that has to be > specified. The outputs are numbered 0 to 4. > > Moreover, I could have specified a different array base, and the loop > remains unchanged.) Janis [*] Read it as "GNU Awk", since in that variant (as opposed to standard Awk) you can control the 'for' iteration order.