• Re: Checking the loop variable after the loop has ended (Was: Loops (wa

    From Rosario19@21:1/5 to bart on Thu Apr 24 22:43:32 2025
    On Fri, 18 Apr 2025 16:07:03 +0100, bart wrote:

    for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;

    using goto label would be as this

    n=NUM_ENTRIES
    L: if(!((n >= 0) && (node[n] != key))) goto Ex
    --n; goto L;
    Ex:

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to All on Fri Apr 25 07:50:15 2025
    On 24.04.2025 22:43, Rosario19 wrote:
    On Fri, 18 Apr 2025 16:07:03 +0100, bart wrote:

    for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;

    using goto label would be as this

    n=NUM_ENTRIES
    L: if(!((n >= 0) && (node[n] != key))) goto Ex
    --n; goto L;
    Ex:


    You are just showing a low-level transformation of a higher-level
    construct. (I'm sure the professional folks here are familiar with
    such transformations.)

    You are not [seriously] suggesting to use that 'goto' based form
    instead of the 'for' loop, do you?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Janis Papanagnou on Fri Apr 25 07:04:53 2025
    On 25/04/2025 06:50, Janis Papanagnou wrote:
    On 24.04.2025 22:43, Rosario19 wrote:
    On Fri, 18 Apr 2025 16:07:03 +0100, bart wrote:

    for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;

    using goto label would be as this

    n=NUM_ENTRIES
    L: if(!((n >= 0) && (node[n] != key))) goto Ex
    --n; goto L;
    Ex:


    You are just showing a low-level transformation of a higher-level
    construct. (I'm sure the professional folks here are familiar with
    such transformations.)

    You are not [seriously] suggesting to use that 'goto' based form
    instead of the 'for' loop, do you?


    That's exactly the kind of thing that should be considered harmful.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rosario19@21:1/5 to All on Fri Apr 25 10:38:03 2025
    On Thu, 24 Apr 2025 22:43:32 +0200, Rosario19 wrote:

    On Fri, 18 Apr 2025 16:07:03 +0100, bart wrote:

    for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;

    using goto label would be as this

    n=NUM_ENTRIES
    L: if(!((n >= 0) && (node[n] != key))) goto Ex
    --n; goto L;
    Ex:

    n=NUM_ENTRIES
    L: if(n<0 || node[n]==key)goto Ex; --n; goto L;
    Ex:

    this is more clear of above... yes if one is accostumated to use
    for(;;) loop this would be better

    for(n=NUM_ENTRIES;n>=0 && node[n]!=key; --n);

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rosario19@21:1/5 to All on Fri Apr 25 10:42:50 2025
    On Fri, 25 Apr 2025 10:38:03 +0200, Rosario19 <Ros@invalid.invalid>
    wrote:

    for (n = NUM_ENTRIES; (n >= 0) && (node[n] != key); --n) continue;

    this code has a bug if array "node" has lenght less or ugual to
    NUM_ENTRIES, so the lenght of "node" has to be at last NUM_ENTRIES+1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)