Jump to content

Loops/Wrong ranges: Difference between revisions

Line 1,074:
Start equal stop equal zero: zero increment [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] (loops forever)
</pre>
 
=={{header|jq}}==
 
jq has a filter `range(start; stop; increment)` which emits a
(possibly empty) stream of numbers if given numeric inputs.
 
It meets the task criterion, e.g. `range(0;1;0.4)` generates 3 numbers.
 
In fact, it is quite similar to C's `for (i=start; i < stop; i+=increment)`
except that if `increment` is 0 or in the "wrong" direction, then nothing is emitted.
 
None of the cases enumerated in the task description results in an error,
and in all but two cases, the result is the empty stream.
 
To streamline the presentation of results, rather than showing the stream
of values generated by stream(start;stop;increment), we will show the
array of the generated values.
<pre>
[range(-2; 2; 1)] #=> [-2,-1,0,1]
 
[range(-2; 2; 0)] #=> []
 
[range(-2; 2; -1)] #=> []
 
[range(-2; 2; 10)] # [-2]
 
[range(2; -2; 1)] #=> []
 
[range(2; 2; 1)] #=> []
 
[range(2; 2; 0)] #=> []
 
[range(0; 0; -1)] #=> []
</pre>
 
 
 
=={{header|Julia}}==
2,484

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.