Ignore:
Timestamp:
Mar 11, 2026, 5:44:52 PM (6 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.