Loops/Wrong ranges: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added zkl header) |
(→{{header|zkl}}: added zode) |
||
Line 423: | Line 423: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
<lang zkl>// zero increment (ie infnite loop) throws an error |
|||
<lang zkl></lang> |
|||
// if stop is "*", the loop is has no end (ie infinite) |
|||
<lang zkl></lang> |
|||
// stop is included unless step steps skips it |
|||
// if start > stop is a dead loop |
|||
// ranges ([a..b,c]) are lazy lists |
|||
fcn looper([(start,stop,increment)]){ |
|||
print(" %3s %3s\t%2d --> ".fmt(start,stop,increment)); |
|||
if(increment!=0){ foreach n in ([start..stop,increment]){ print(n," ") } } |
|||
println(); |
|||
} |
|||
println("start stop increment"); |
|||
T( T(-2,2,1),T(-2,2,0),T(-2,2,-1),T(-2,2,10),T( 2,-2,1), |
|||
T( 2,2,1),T( 2,2,-1),T( 2,2,0),T( 0,0,0), |
|||
T(0.0, (0.0).pi, 0.7853981633974483), T("a","e",1), T("e","a",1) ) |
|||
.apply2(looper);</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
start stop increment |
|||
-2 2 1 --> -2 -1 0 1 2 |
|||
-2 2 0 --> |
|||
-2 2 -1 --> |
|||
-2 2 10 --> -2 |
|||
2 -2 1 --> |
|||
2 2 1 --> 2 |
|||
2 2 -1 --> 2 |
|||
2 2 0 --> |
|||
0 0 0 --> |
|||
0 3.14159 0 --> 0 0.785398 1.5708 2.35619 3.14159 |
|||
a e 1 --> a b c d e |
|||
e a 1 --> |
|||
</pre> |
</pre> |