Deutsch English Français Italiano |
<vtr04m$m6l8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.nobody.at!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: Thu, 17 Apr 2025 14:36:22 +0100 Organization: A noiseless patient Spider Lines: 34 Message-ID: <vtr04m$m6l8$1@dont-email.me> References: <vspbjh$8dvd$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> <20250416142925.663@kylheku.com> <vtpbnm$357ma$2@dont-email.me> <20250416164536.110@kylheku.com> <vtpj5h$3duft$1@dont-email.me> <87ikn3zg18.fsf@nosuchdomain.example.com> <vtqnv9$hf83$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 17 Apr 2025 15:36:22 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4c8a6fcf63bfdc2f0026c4e2b7cdaca7"; logging-data="727720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MElH/WsauP34Lvz4LLwK4" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:DnOn2qvdsTVvnuVMMz4vrY5NuSY= Content-Language: en-GB In-Reply-To: <vtqnv9$hf83$1@dont-email.me> Bytes: 3084 On 17/04/2025 12:16, bart wrote: > On 17/04/2025 03:18, Keith Thompson wrote: >> If you want to implement, say, an Ada-style for loop, detecting >> overflow is not an issue at the language level. The issue is that >> for the following (I think the Ada syntax is clear enough): >> >> for I in Integer'Last-1 .. Integer'Last loop >> // whatever >> end loop; >> >> the language semantics specify that the body of the loop must be >> executed with I equal to Integer'Last-1, and then with I equal to >> Integer'Last. It's the compiler's job to figure out how to do that, >> either without triggering an overflow or by handling it cleanly enough >> that it doesn't change the behavior. > > Does it define what value I has when the loop terminates, or is the > scope of I local to the loop body? My experiments show that: (1) Loop variables only have scope within the loop (2) Loop variables are read-only; they cannot be modified by user code This makes it much simpler to get the desired behaviour of a loop index iterating up to the maximum value of the type. So a comparison with other languages (either C or mine) is not that fair. Mine can be more restrictive, and I can make it more so (eg. restrict the scope of loop variables), but I have no interest in reimplementing Ada.