Loops/Wrong ranges: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: Minor fix for recent rule change for stricter caching of sequences) |
(add FreeBASIC) |
||
Line 395: | Line 395: | ||
0 0 0 <range> => Exception: divide by zero. |
0 0 0 <range> => Exception: divide by zero. |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>data -2,2,1,"Normal",-2,2,0,"Zero increment",-2,2,-1,"Increments away from stop value" |
|||
data -2,2,10,"First increment is beyond stop value",2,-2,1,"Start more than stop: positive increment" |
|||
data 2,2,1,"Start equal stop: positive increment",2,2,-1,"Start equal stop: negative increment" |
|||
data 2,2,0,"Start equal stop: zero increment",0,0,0,"Start equal stop equal zero: zero increment" |
|||
dim as integer i, start, fin, inc, vr, count |
|||
dim as string cmt |
|||
for i = 1 to 9 |
|||
count = 0 |
|||
read start, fin, inc, cmt |
|||
print cmt |
|||
print using " Looping from ### to ### in increments of ##"; start; fin; inc |
|||
for vr = start to fin step inc |
|||
print " Loop index = ",vr |
|||
count += 1 |
|||
if count = 10 then |
|||
print " Breaking infinite loop" |
|||
exit for |
|||
end if |
|||
next vr |
|||
print " Loop finished" |
|||
print |
|||
print |
|||
next i |
|||
</lang> |
|||
{{out}} |
|||
<pre>Normal |
|||
Looping from -2 to 2 in increments of 1 |
|||
Loop index = -2 |
|||
Loop index = -1 |
|||
Loop index = 0 |
|||
Loop index = 1 |
|||
Loop index = 2 |
|||
Loop finished |
|||
Zero increment |
|||
Looping from -2 to 2 in increments of 0 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Loop index = -2 |
|||
Breaking infinite loop |
|||
Loop finished |
|||
Increments away from stop value |
|||
Looping from -2 to 2 in increments of -1 |
|||
Loop finished |
|||
First increment is beyond stop value |
|||
Looping from -2 to 2 in increments of 10 |
|||
Loop index = -2 |
|||
Loop finished |
|||
Start more than stop: positive increment |
|||
Looping from 2 to -2 in increments of 1 |
|||
Loop finished |
|||
Start equal stop: positive increment |
|||
Looping from 2 to 2 in increments of 1 |
|||
Loop index = 2 |
|||
Loop finished |
|||
Start equal stop: negative increment |
|||
Looping from 2 to 2 in increments of -1 |
|||
Loop index = 2 |
|||
Loop finished |
|||
Start equal stop: zero increment |
|||
Looping from 2 to 2 in increments of 0 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Loop index = 2 |
|||
Breaking infinite loop |
|||
Loop finished |
|||
Start equal stop equal zero: zero increment |
|||
Looping from 0 to 0 in increments of 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Loop index = 0 |
|||
Breaking infinite loop |
|||
Loop finished</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |