Loops/Wrong ranges: Difference between revisions

m
→‎{{header|Perl 6}}: some more exposition
(Added Go)
m (→‎{{header|Perl 6}}: some more exposition)
Line 142:
# only show up to the first 15 elements of possibly infinite sequences
put $seq[^15].grep: +*.so
}
}</lang>
 
# For that matter the start and end values don't need to be numeric either. Both
# or either can be a function, list, or other object. Really anything that a
# "successor" function can be defined for and produces a value.
 
# Start with a list, iterate by multiplying the previous 3 terms together
# and end with a term defined by a function.
put 1, -.5, 2.sqrt, * * * * * … *.abs < 1e-2;
 
# Start with an array, iterate by rotating, end when 0 is in the last place.
say [0,1,2,3,4,5], *.rotate(-1) … !*.tail;
 
# Iterate through strings.
put 'a' … 'h';</lang>
{{out}}
<pre>Start: -2, Stop: 2, Increment: 1 | -2 -1 0 1 2
Start: -2, Stop: 2, Increment: 0 | -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
Start: -2, Stop: 2, Increment: -1 | -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16
Line 151 ⟶ 165:
Start: 2, Stop: 2, Increment: 1 | 2
Start: 2, Stop: 2, Increment: 0 | 2
Start: 0, Stop: 0, Increment: 0 | 0
Start: 1, Stop: Inf, Increment: 3 | 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43
Start: 01, Stop: 3.141592653589793 2, Increment: 0.7853981633974483 | 01 0.78539816339744831 1.5707963267948966 2.3561944901923451 3.1415926535897931 1 1 1 1 1 1 1 1 1 1
Start: 0, Stop: 3.141592653589793, Increment: 0.7853981633974483 | 0.7853981633974483 1.5707963267948966 2.356194490192345 3.141592653589793
Start: 1.4, Stop: *, Increment: -7.1 | 1.4 -5.7 -12.8 -19.9 -27 -34.1 -41.2 -48.3 -55.4 -62.5 -69.6 -76.7 -83.8 -90.9 -98</pre>
1 -0.5 1.4142135623730951 -0.7071067811865476 0.5000000000000001 -0.5000000000000002 0.176776695296637 -0.04419417382415928 0.0039062500000000095
([0 1 2 3 4 5] [5 0 1 2 3 4] [4 5 0 1 2 3] [3 4 5 0 1 2] [2 3 4 5 0 1] [1 2 3 4 5 0])
a b c d e f g h</pre>
 
=={{header|Python}}==
10,333

edits