• Re: Sort of trivial code challenge - may be interesting to you anyway

    From Tim Rentsch@tr.17687@z991.linuxsc.com to comp.lang.c on Mon Apr 6 12:02:25 2026
    From Newsgroup: comp.lang.c

    Bart <bc@freeuk.com> writes:

    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.

    I was responding to a context where the prohibitions had already
    been violated. I was simply pointing out that if those rules are
    going to be ignored then there are easier ways to solve the problem
    than importing exotic control structures from other languages.
    --- Synchronet 3.21f-Linux NewsLink 1.2