Debian Codegraph @

examples/ctrl/ctrl_foreach.ck

raw
1 //-------------------------------------------------------
2 // name: ctrl_foreach.ck
3 // desc: for-each construct to loop over arrays
4 //
5 // requires: chuck-1.5.0.8 or higher
6 //
7 // SEE ALSO: examples/array/foreach-*.ck for more
8 //-------------------------------------------------------
9
10 // create empty array
11 float array[0];
12
13 // append
14 array << 1 << 2.5 << 3;
15
16 // for each element 'x' in array
17 for( float x : array )
18 {
19 // print the element
20 <<< x >>>;
21 }
22
23 // iterating over an array literal
24 for( int x : [ 1, 2, 3 ] )
25 {
26 // do something with it
27 <<< x >>>;
28 }