On 15/03/2026 22:54, Tim Rentsch wrote:
Bart <bc@freeuk.com> 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++;
}
}
Yes, but you'd prohibited many standard features including loops for
your challenge.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,113 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 492356:17:29 |
| Calls: | 14,243 |
| Files: | 186,313 |
| D/L today: |
201 files (26,917K bytes) |
| Messages: | 2,515,337 |