Changeset 4c5ce70


Ignore:
Timestamp:
Mar 11, 2026, 5:44:52 PM (2 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
a783c74
Parents:
42bce4e
Message:

update loop else-clause test to verify loop declarations are accessible in else clause

Location:
tests/ctrl-flow
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/ctrl-flow/.expect/loop_else.txt

    r42bce4e r4c5ce70  
    6969(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)(0 0)else
    7070
    71 before begin else after
     71before
     72 begin
     73 else
     74 after
     75key 11 not found at position 10
     76key 11 not found at position 10
  • tests/ctrl-flow/loop_else.cfa

    r42bce4e r4c5ce70  
    123123        sout | nl;
    124124
     125        sout | nlOn;                                                                            // turn on auto newline
     126
    125127        // A break (or a continue) in an else clause should target an outer loop.
    126128
     
    136138                sout | " end";
    137139        }
    138         sout | " after" | nl;
     140        sout | " after";
     141
     142        // A loop index for while and for is accessible in the else clause.
     143        // Do-while has no local declarations in condition.
     144
     145        int key = 11, size = 10, arr[size] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     146        while ( int i = 0; i < size ) {
     147                if ( arr[i] == key ) sout | "key" | key | "found at posstion" | i;
     148                i += 1;
     149        } else sout | "key" | key | "not found at position" | i;
     150                       
     151        for ( i; size ) {
     152                if ( arr[i] == key ) sout | "key" | key | "found at posstion" | i;
     153        } else sout | "key" | key | "not found at position" | i;
    139154}
Note: See TracChangeset for help on using the changeset viewer.