Loops/Wrong ranges: Difference between revisions

Content added Content deleted
Line 102: Line 102:
Start equal stop: zero increment : 2 2 2 2 2 2 2 2 2 2
Start equal stop: zero increment : 2 2 2 2 2 2 2 2 2 2
Start equal stop equal zero: zero increment : 0 0 0 0 0 0 0 0 0 0
Start equal stop equal zero: zero increment : 0 0 0 0 0 0 0 0 0 0
</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f LOOPS_WRONG_RANGES.AWK
BEGIN {
arr[++n] = "-2, 2, 1,Normal"
arr[++n] = "-2, 2, 0,Zero increment"
arr[++n] = "-2, 2,-1,Increments away from stop value"
arr[++n] = "-2, 2,10,First increment is beyond stop value"
arr[++n] = " 2,-2, 1,Start more than stop: positive increment"
arr[++n] = " 2, 2, 1,Start equal stop: positive increment"
arr[++n] = " 2, 2,-1,Start equal stop: negative increment"
arr[++n] = " 2, 2, 0,Start equal stop: zero increment"
arr[++n] = " 0, 0, 0,Start equal stop equal zero: zero increment"
print("start,stop,increment,comment")
for (i=1; i<=n; i++) {
split(arr[i],A,",")
printf("%-52s : ",arr[i])
count = 0
for (j=A[1]; j<=A[2] && count<10; j+=A[3]) {
printf("%d ",j)
count++
}
printf("\n")
}
exit(0)
}
</lang>
{{out}}
<pre>
start,stop,increment,comment
-2, 2, 1,Normal : -2 -1 0 1 2
-2, 2, 0,Zero increment : -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
-2, 2,-1,Increments away from stop value : -2 -3 -4 -5 -6 -7 -8 -9 -10 -11
-2, 2,10,First increment is beyond stop value : -2
2,-2, 1,Start more than stop: positive increment :
2, 2, 1,Start equal stop: positive increment : 2
2, 2,-1,Start equal stop: negative increment : 2 1 0 -1 -2 -3 -4 -5 -6 -7
2, 2, 0,Start equal stop: zero increment : 2 2 2 2 2 2 2 2 2 2
0, 0, 0,Start equal stop equal zero: zero increment : 0 0 0 0 0 0 0 0 0 0
</pre>
</pre>