Deutsch English Français Italiano |
<vttntl$3468v$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Fri, 18 Apr 2025 15:34:28 +0100 Organization: A noiseless patient Spider Lines: 68 Message-ID: <vttntl$3468v$2@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> <vttig0$32ksb$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 18 Apr 2025 16:34:29 +0200 (CEST) Injection-Info: dont-email.me; posting-host="225decbae7f6d1b66db568edbb209aee"; logging-data="3283231"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19M6ku7syVYFGSOu+R0Fbv4" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:vl4AAJHP7rGGUWawuZitcH+J1IA= Content-Language: en-GB In-Reply-To: <vttig0$32ksb$1@dont-email.me> Bytes: 4079 On 18/04/2025 14:01, Janis Papanagnou wrote: > 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".) It highlights three things that C manages to make quite a meal out of, despite them being trivially fixable even in such a low-level language: * The for-loop as has been discussed at length * Getting at the length of a fixed-size array * Needing to use format codes to print things (I don't want to know how you can use macros to mitigate some of these; at that point it's already failed.) >> 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.) I had to check your claims: * Awk primarily uses a C-style for loop; using 'for in' is an alternative (it's not clear if this is specific to gnu-Awk) * 'i in table' iterates over /indices/, not values as is more typical of languages that support 'in'. (In my stuff, I'd need 'i in table.bounds' to get at the indices, or use an auxiliary loop variable as shown above.)