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: <20250413072027.219@kylheku.com> <20250415053852.166@kylheku.com> 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 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