Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
Date: Sun, 15 Mar 2026 15:54:52 -0700
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <86h5qg66v7.fsf@linuxsc.com>
References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <20260302110720.00007698@yahoo.com> <86qzq2e1u3.fsf@linuxsc.com> <10o4ilk$1bo87$1@dont-email.me> <86ikbdebo8.fsf@linuxsc.com> <10o7he5$2cb17$1@dont-email.me> <865x718b5q.fsf@linuxsc.com> <10p0u54$32bhs$1@dont-email.me> <10p24th$3mc94$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Sun, 15 Mar 2026 22:54:58 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="37fbd2bc0a39a2e0da8dcfefffa00bf6"; logging-data="1460169"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zghE0WwZLrycLYw3u9NniAs/B7kaQdCE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:0S/hxj45yC2cYxh2+PGQ5AHNoN4= sha1:onLDSvwfsxtjVZws4zGUpz3v3BY=
Xref: csiph.com comp.lang.c:397010
Bart writes:
> On 13/03/2026 11:58, Bart wrote:
>
> [characterizing my earlier code as a finite state machine]
>
>> Ideally it would just have a loop. (In my languages, there is a
>> feature called 'doswitch',
>
> I ported this (C version using 'goto') to my scripting language just
> to see what it would look like:
>
> https://github.com/sal55/langs/blob/master/tr.q
>
> This doesn't use 'goto', nor conventional loops. However 'doswitch'
> does loop.
>
> An alternative method could use 'recase' (in C terms, jumping directly
> to a case label). It's just goto 'under the hood', but much less
> underhand than 'longjmp'.
>
> Other ways of control flow include label pointers (also in some C
> extensions).
None of these more elaborate control structures are needed. The
board display behavior can easily be expressed using conventional
control structures, in standard C:
void
show_board( unsigned height, unsigned width, unsigned cutoff ){
const int D = digits_width( cutoff );
const unsigned R = cutoff < height ? cutoff : height;
unsigned r = 0, c = 0;
while( r < R ){
unsigned v = r + c*height;
if( v < cutoff ) printf( " %*u", D, v+1 );
if( ++c >= width ) putchar( '\n' ), c = 0, r++;
}
}