| Deutsch English Français Italiano |
|
<20250415154221.631@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: Loops (was Re: do { quit; } else { })
Date: Wed, 16 Apr 2025 01:41:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <20250415154221.631@kylheku.com>
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>
Injection-Date: Wed, 16 Apr 2025 03:41:30 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="43d283a6790c1e441f00fcbbbcc44cba";
logging-data="1072282"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XTfWlWgYDHLgNkuK/M72srQWBflBjZg0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:kCdjOl+BZ6KGBCpTRKCYmJRP4hY=
On 2025-04-15, bart <bc@freeuk.com> wrote:
> Note that C's for-loop is dumb; it merely take three expressions A B C
> that can be completely unrelated, and arranges them into a loop:
>
> A; while (B) {...; C}
- In this proposed arrangement, if the "continue" keyword is used in the
loop, it will not execute C. You need:
A; while (B) {...; contin_001: C}
and then use "goto contin_001". The 001 is for uniqueness within
the function, to which labels are scoped.
- the arrangement doesn't produce macros very well using the
ordinary preprocessor. Suppose we want to create loop which
steps by 1 from hither to yon:
#define loop_start(A, B, C) do { A = B; while (A < C) {
#define loop_end(A) A++; } } while (0)
we end up with two macros, where we have to repeat the variable.
With the for loop we can just do
#define loop(A, B, C) for (A = B; A < C; A++)
Good thing we have that for syntax with its compact, encapsulated
header that holds all the parts needed.
If you keep plugging away with the naked "for" without making yourself a
convenient macro, that's your problem.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca