Loops/Wrong ranges: Difference between revisions

Added Chipmunk Basic, GW-BASIC, Minimal BASIC, MSX Basic and Quite BASIC. Grouping BASIC dialects
m (add RPL)
(Added Chipmunk Basic, GW-BASIC, Minimal BASIC, MSX Basic and Quite BASIC. Grouping BASIC dialects)
Line 261:
</pre>
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang="applesoftbasic">0 LIMIT = 10 :MAX=1E37
10 DATA-2,2,1,NORMAL
20 DATA-2,2,0,ZERO INCREMENT
30 DATA-2,2,-1,INCREMENTS AWAY FROM STOP VALUE
40 DATA-2,2,10,FIRST INCREMENT IS BEYOND STOP VALUE
50 DATA2,-2,1,"START MORE THAN STOP: POSITIVE INCREMENT
60 DATA2,2,1,"START EQUAL STOP: POSITIVE INCREMENT
70 DATA2,2,-1,"START EQUAL STOP: NEGATIVE INCREMENT
80 DATA2,2,0,"START EQUAL STOP: ZERO INCREMENT
90 DATA0,0,0,"START EQUAL STOP EQUAL ZERO: ZERO INCREMENT
100 FOR I = 1 TO 9
110 READ START,FINISH,INCR,COMMENT$
120 PRINT CHR$(13)COMMENT$
130 LAST = FINISH
140 REM D = SGN(FINISH - START)
150 REM IF D AND NOT (D = SGN(INCR)) THEN LAST = SGN(INCR)*MAX
160 PRINT TAB(5)CHR$(91)" "MID$(" ",(START<0)+1)START" TO "MID$(" ",(FINISH<0)+1)FINISH" STEP "MID$(" ",(INCR<0)+1)INCR" ] ";
170 COUNT = 0
180 PRINT MID$(" ",(START<0)+1);
190 FOR J = START TO LAST STEP INCR
200 PRINT MID$(" ",(COUNT=0)+1)J;
210 IF COUNT < LIMIT THEN COUNT = COUNT + 1 : NEXT J
220 IF COUNT = LIMIT THEN PRINT " ... ";:if ABS(LAST) = MAX THEN PRINT MID$("-",SGN(LAST)+2,1)"INFINITY";
230 NEXT I</syntaxhighlight>
{{out}}
<pre>
NORMAL
[ -2 TO 2 STEP 1 ] -2 -1 0 1 2
ZERO INCREMENT
[ -2 TO 2 STEP 0 ] -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 ...
INCREMENTS AWAY FROM STOP VALUE
[ -2 TO 2 STEP -1 ] -2
FIRST INCREMENT IS BEYOND STOP VALUE
[ -2 TO 2 STEP 10 ] -2
START MORE THAN STOP: POSITIVE INCREMENT
[ 2 TO -2 STEP 1 ] 2
START EQUAL STOP: POSITIVE INCREMENT
[ 2 TO 2 STEP 1 ] 2
START EQUAL STOP: NEGATIVE INCREMENT
[ 2 TO 2 STEP -1 ] 2
START EQUAL STOP: ZERO INCREMENT
[ 2 TO 2 STEP 0 ] 2
START EQUAL STOP EQUAL ZERO: ZERO INCREMENT
[ 0 TO 0 STEP 0 ] 0
</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">print "start stop increment"
 
Line 329 ⟶ 282:
]
</syntaxhighlight>
 
{{out}}
 
<pre>start stop increment
-2 2 1 -> [-2 -1 0 1 2]
Line 371 ⟶ 322:
</syntaxhighlight>
{{out}}
<pre>start,stop,increment,comment
<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
Line 381 ⟶ 331:
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>
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">0 LIMIT = 10 :MAX=1E37
10 DATA-2,2,1,NORMAL
20 DATA-2,2,0,ZERO INCREMENT
30 DATA-2,2,-1,INCREMENTS AWAY FROM STOP VALUE
40 DATA-2,2,10,FIRST INCREMENT IS BEYOND STOP VALUE
50 DATA2,-2,1,"START MORE THAN STOP: POSITIVE INCREMENT
60 DATA2,2,1,"START EQUAL STOP: POSITIVE INCREMENT
70 DATA2,2,-1,"START EQUAL STOP: NEGATIVE INCREMENT
80 DATA2,2,0,"START EQUAL STOP: ZERO INCREMENT
90 DATA0,0,0,"START EQUAL STOP EQUAL ZERO: ZERO INCREMENT
100 FOR I = 1 TO 9
110 READ START,FINISH,INCR,COMMENT$
120 PRINT CHR$(13)COMMENT$
130 LAST = FINISH
140 REM D = SGN(FINISH - START)
150 REM IF D AND NOT (D = SGN(INCR)) THEN LAST = SGN(INCR)*MAX
160 PRINT TAB(5)CHR$(91)" "MID$(" ",(START<0)+1)START" TO "MID$(" ",(FINISH<0)+1)FINISH" STEP "MID$(" ",(INCR<0)+1)INCR" ] ";
170 COUNT = 0
180 PRINT MID$(" ",(START<0)+1);
190 FOR J = START TO LAST STEP INCR
200 PRINT MID$(" ",(COUNT=0)+1)J;
210 IF COUNT < LIMIT THEN COUNT = COUNT + 1 : NEXT J
220 IF COUNT = LIMIT THEN PRINT " ... ";:if ABS(LAST) = MAX THEN PRINT MID$("-",SGN(LAST)+2,1)"INFINITY";
230 NEXT I</syntaxhighlight>
{{out}}
<pre>
NORMAL
[ -2 TO 2 STEP 1 ] -2 -1 0 1 2
ZERO INCREMENT
[ -2 TO 2 STEP 0 ] -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 ...
INCREMENTS AWAY FROM STOP VALUE
[ -2 TO 2 STEP -1 ] -2
FIRST INCREMENT IS BEYOND STOP VALUE
[ -2 TO 2 STEP 10 ] -2
START MORE THAN STOP: POSITIVE INCREMENT
[ 2 TO -2 STEP 1 ] 2
START EQUAL STOP: POSITIVE INCREMENT
[ 2 TO 2 STEP 1 ] 2
START EQUAL STOP: NEGATIVE INCREMENT
[ 2 TO 2 STEP -1 ] 2
START EQUAL STOP: ZERO INCREMENT
[ 2 TO 2 STEP 0 ] 2
START EQUAL STOP EQUAL ZERO: ZERO INCREMENT
[ 0 TO 0 STEP 0 ] 0</pre>
 
==={{header|BASIC256}}===
{{trans|Yabasic}}
<syntaxhighlight lang="freebasic">arraybase 1
Line 415 ⟶ 411:
{{out}}
<pre>Igual que la entrada de Yabasic.</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 cls
110 for i = 1 to 9
120 contar = 0
130 read start,fin,inc,cmt$
140 print cmt$
150 print " Bucle de ";start;"a ";fin;" en incrementos de ";inc
160 for vr = start to fin step inc
170 print " Indice del bucle = ";vr
180 contar = contar+1
190 if contar = 10 then
200 print " Saliendo de un bucle infinito"
210 goto 240
220 endif
230 next vr
240 print " Bucle terminado" : print : print
250 next i
260 end
270 data -2,2,1,"Normal",-2,2,0,"Zero increment",-2,2,-1,"Increments away from stop value"
280 data -2,2,10,"First increment is beyond stop value",2,-2,1,"Start more than stop: positive increment"
290 data 2,2,1,"Start equal stop: positive increment",2,2,-1,"Start equal stop: negative increment"
300 data 2,2,0,"Start equal stop: zero increment",0,0,0,"Start equal stop equal zero: zero increment"</syntaxhighlight>
{{out}}
<pre>Normal
Bucle de -2 a 2 en incrementos de 1
Indice del bucle = -2
Indice del bucle = -1
Indice del bucle = 0
Indice del bucle = 1
Indice del bucle = 2
Bucle terminado
 
 
Zero increment
Bucle de -2 a 2 en incrementos de 0
Bucle terminado
 
 
Increments away from stop value
Bucle de -2 a 2 en incrementos de -1
Bucle terminado
 
 
First increment is beyond stop value
Bucle de -2 a 2 en incrementos de 10
Indice del bucle = -2
Bucle terminado
 
 
Start more than stop: positive increment
Bucle de 2 a -2 en incrementos de 1
Bucle terminado
 
 
Start equal stop: positive increment
Bucle de 2 a 2 en incrementos de 1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: negative increment
Bucle de 2 a 2 en incrementos de -1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: zero increment
Bucle de 2 a 2 en incrementos de 0
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Saliendo de un bucle infinito
Bucle terminado
 
 
Start equal stop equal zero: zero increment
Bucle de 0 a 0 en incrementos de 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Saliendo de un bucle infinito
Bucle terminado</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight 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
</syntaxhighlight>
{{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|GW-BASIC}}===
The [[#Chipmunk Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Minimal BASIC}}===
{{works with|QBasic}}
{{works with|QuickBasic}}
{{works with|Applesoft BASIC}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 CLS : REM 100 HOME for Applesoft BASIC : REM DELETE line for Minimal BASIC
110 DATA -2,2,1,"Normal",-2,2,0,"Zero increment"
120 DATA -2,2,-1,"Increments away from stop value"
130 DATA -2,2,10,"First increment is beyond stop value"
140 DATA 2,-2,1,"Start more than stop: positive increment"
150 DATA 2,2,1,"Start equal stop: positive increment"
160 DATA 2,2,-1,"Start equal stop: negative increment"
170 DATA 2,2,0,"Start equal stop: zero increment"
180 DATA 0,0,0,"Start equal stop equal zero: zero increment"
190 FOR j = 1 TO 9
200 LET c = 0
210 READ s, f, i, t$
220 PRINT t$
230 PRINT " Bucle de "; s; "a "; f; " en incrementos de "; i
240 FOR v = s TO f STEP i
250 PRINT " Indice del bucle = "; v
260 LET c = c + 1
270 IF c <> 10 THEN 300
280 PRINT " Saliendo de un bucle infinito"
290 GOTO 310
300 NEXT v
310 PRINT " Bucle terminado"
320 PRINT
330 NEXT j
340 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#Chipmunk Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Quite BASIC}}===
See solution [[#Minimal BASIC|Minimal BASIC]]
 
==={{header|Visual Basic .NET}}===
'''Compiler:''' >= Visual Studio 2012
 
VB.NET's For loop accepts a starting and ending value and optional step.
 
Since the task mentions generators and a range of values, this implementation places the for loop in an iterator function (called a generator in many other languages) and yields the iteration variable in every iteration. The resulting IEnumerable object (whose actual class is generated by the compiler) is lazily-evaluated (i.e., it is run only when a new value is requested, and only until the next Yield statement).
 
The number of iterations is limited to 10 by the test code.
 
<syntaxhighlight lang="vbnet">Module Program
Sub Main()
Example(-2, 2, 1, "Normal")
Example(-2, 2, 0, "Zero increment")
Example(-2, 2, -1, "Increments away from stop value")
Example(-2, 2, 10, "First increment is beyond stop value")
Example(2, -2, 1, "Start more than stop: positive increment")
Example(2, 2, 1, "Start equal stop: positive increment")
Example(2, 2, -1, "Start equal stop: negative increment")
Example(2, 2, 0, "Start equal stop: zero increment")
Example(0, 0, 0, "Start equal stop equal zero: zero increment")
End Sub
 
' Stop is a keyword and must be escaped using brackets.
Iterator Function Range(start As Integer, [stop] As Integer, increment As Integer) As IEnumerable(Of Integer)
For i = start To [stop] Step increment
Yield i
Next
End Function
 
Sub Example(start As Integer, [stop] As Integer, increment As Integer, comment As String)
' Add a space, pad to length 50 with hyphens, and add another space.
Console.Write((comment & " ").PadRight(50, "-"c) & " ")
 
Const MAX_ITER = 9
 
Dim iteration = 0
' The For Each loop enumerates the IEnumerable.
For Each i In Range(start, [stop], increment)
Console.Write("{0,2} ", i)
 
iteration += 1
If iteration > MAX_ITER Then Exit For
Next
 
Console.WriteLine()
End Sub
End Module</syntaxhighlight>
{{out}}
<pre>Normal ------------------------------------------- -2 -1 0 1 2
Zero increment ----------------------------------- -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
Increments away from stop value ------------------
First increment is beyond stop value ------------- -2
Start more than stop: positive increment ---------
Start equal stop: positive increment ------------- 2
Start equal stop: negative increment ------------- 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</pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">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"
 
for i = 1 to 9
contar = 0
read start, fin, inc, cmt$
print cmt$
print " Bucle de ", start, " a ", fin, " en incrementos de ", inc
for vr = start to fin step inc
print " Indice del bucle = ", vr
contar = contar + 1
if contar = 10 then
print " Saliendo de un bucle infinito"
break
endif
next vr
print " Bucle terminado\n\n"
next i
end</syntaxhighlight>
{{out}}
<pre>Normal
Bucle de -2 a 2 en incrementos de 1
Indice del bucle = -2
Indice del bucle = -1
Indice del bucle = 0
Indice del bucle = 1
Indice del bucle = 2
Bucle terminado
 
 
Zero increment
Bucle de -2 a 2 en incrementos de 0
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Saliendo de un bucle infinito
Bucle terminado
 
 
Increments away from stop value
Bucle de -2 a 2 en incrementos de -1
Bucle terminado
 
 
First increment is beyond stop value
Bucle de -2 a 2 en incrementos de 10
Indice del bucle = -2
Bucle terminado
 
 
Start more than stop: positive increment
Bucle de 2 a -2 en incrementos de 1
Bucle terminado
 
 
Start equal stop: positive increment
Bucle de 2 a 2 en incrementos de 1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: negative increment
Bucle de 2 a 2 en incrementos de -1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: zero increment
Bucle de 2 a 2 en incrementos de 0
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Saliendo de un bucle infinito
Bucle terminado
 
 
Start equal stop equal zero: zero increment
Bucle de 0 a 0 en incrementos de 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Saliendo de un bucle infinito
Bucle terminado</pre>
 
=={{header|C}}==
Line 947 ⟶ 1,365:
start: 0 stop: 0 inc: 0 |
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight 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
</syntaxhighlight>
{{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}}==
Line 2,477 ⟶ 2,783:
0 0 0 | 0,0,0,0,0,0,0,0,0,0,0,
Start equal stop equal zero: zero increment</pre>
 
=={{header|Visual Basic .NET}}==
'''Compiler:''' >= Visual Studio 2012
 
VB.NET's For loop accepts a starting and ending value and optional step.
 
Since the task mentions generators and a range of values, this implementation places the for loop in an iterator function (called a generator in many other languages) and yields the iteration variable in every iteration. The resulting IEnumerable object (whose actual class is generated by the compiler) is lazily-evaluated (i.e., it is run only when a new value is requested, and only until the next Yield statement).
 
The number of iterations is limited to 10 by the test code.
 
<syntaxhighlight lang="vbnet">Module Program
Sub Main()
Example(-2, 2, 1, "Normal")
Example(-2, 2, 0, "Zero increment")
Example(-2, 2, -1, "Increments away from stop value")
Example(-2, 2, 10, "First increment is beyond stop value")
Example(2, -2, 1, "Start more than stop: positive increment")
Example(2, 2, 1, "Start equal stop: positive increment")
Example(2, 2, -1, "Start equal stop: negative increment")
Example(2, 2, 0, "Start equal stop: zero increment")
Example(0, 0, 0, "Start equal stop equal zero: zero increment")
End Sub
 
' Stop is a keyword and must be escaped using brackets.
Iterator Function Range(start As Integer, [stop] As Integer, increment As Integer) As IEnumerable(Of Integer)
For i = start To [stop] Step increment
Yield i
Next
End Function
 
Sub Example(start As Integer, [stop] As Integer, increment As Integer, comment As String)
' Add a space, pad to length 50 with hyphens, and add another space.
Console.Write((comment & " ").PadRight(50, "-"c) & " ")
 
Const MAX_ITER = 9
 
Dim iteration = 0
' The For Each loop enumerates the IEnumerable.
For Each i In Range(start, [stop], increment)
Console.Write("{0,2} ", i)
 
iteration += 1
If iteration > MAX_ITER Then Exit For
Next
 
Console.WriteLine()
End Sub
End Module</syntaxhighlight>
 
{{out}}
<pre>Normal ------------------------------------------- -2 -1 0 1 2
Zero increment ----------------------------------- -2 -2 -2 -2 -2 -2 -2 -2 -2 -2
Increments away from stop value ------------------
First increment is beyond stop value ------------- -2
Start more than stop: positive increment ---------
Start equal stop: positive increment ------------- 2
Start equal stop: negative increment ------------- 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</pre>
 
=={{header|V (Vlang)}}==
Line 2,656 ⟶ 2,903:
[ 0 0 0] -> 0 0 0 0 0 0 0 0 0 0
</pre>
 
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">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"
 
for i = 1 to 9
contar = 0
read start, fin, inc, cmt$
print cmt$
print " Bucle de ", start, " a ", fin, " en incrementos de ", inc
for vr = start to fin step inc
print " Indice del bucle = ", vr
contar = contar + 1
if contar = 10 then
print " Saliendo de un bucle infinito"
break
endif
next vr
print " Bucle terminado\n\n"
next i
end</syntaxhighlight>
{{out}}
<pre>
Normal
Bucle de -2 a 2 en incrementos de 1
Indice del bucle = -2
Indice del bucle = -1
Indice del bucle = 0
Indice del bucle = 1
Indice del bucle = 2
Bucle terminado
 
 
Zero increment
Bucle de -2 a 2 en incrementos de 0
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Indice del bucle = -2
Saliendo de un bucle infinito
Bucle terminado
 
 
Increments away from stop value
Bucle de -2 a 2 en incrementos de -1
Bucle terminado
 
 
First increment is beyond stop value
Bucle de -2 a 2 en incrementos de 10
Indice del bucle = -2
Bucle terminado
 
 
Start more than stop: positive increment
Bucle de 2 a -2 en incrementos de 1
Bucle terminado
 
 
Start equal stop: positive increment
Bucle de 2 a 2 en incrementos de 1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: negative increment
Bucle de 2 a 2 en incrementos de -1
Indice del bucle = 2
Bucle terminado
 
 
Start equal stop: zero increment
Bucle de 2 a 2 en incrementos de 0
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Indice del bucle = 2
Saliendo de un bucle infinito
Bucle terminado
 
 
Start equal stop equal zero: zero increment
Bucle de 0 a 0 en incrementos de 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Indice del bucle = 0
Saliendo de un bucle infinito
Bucle terminado
</pre>
 
 
=={{header|zkl}}==
2,136

edits