Loops/For with a specified step: Difference between revisions
Content added Content deleted
(Loops/For with a specified step in Dart) |
(Added Chipmunk Basic, GW-BASIC, Minimal BASIC, MSX Basic QBasic, Quite BASIC and Tiny BASIC) |
||
Line 602: | Line 602: | ||
8 |
8 |
||
</pre> |
</pre> |
||
==={{header|Chipmunk Basic}}=== |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="qbasic">10 for i = 1 to 21 step 2 |
|||
20 print i; |
|||
30 next i</syntaxhighlight> |
|||
==={{header|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |
||
Line 633: | Line 639: | ||
for i = 0 to 10 step 2 |
for i = 0 to 10 step 2 |
||
print s(i); |
print s(i); |
||
next</syntaxhighlight> |
|||
next |
|||
{{out}} |
|||
</syntaxhighlight> |
|||
<pre>Somewhere over the rainbow |
|||
Output: |
|||
<pre> |
Bluebirds fly.</pre> |
||
Somewhere over the rainbow |
|||
Bluebirds fly. |
|||
</pre> |
|||
==={{header|Gambas}}=== |
==={{header|Gambas}}=== |
||
Line 651: | Line 654: | ||
End</syntaxhighlight> |
End</syntaxhighlight> |
||
<pre> |
<pre>Gambas is great! |
||
Gambas is great! |
Gambas is great! |
||
Gambas is great! |
Gambas is great! |
||
Line 660: | Line 663: | ||
Gambas is great! |
Gambas is great! |
||
Gambas is great! |
Gambas is great! |
||
Gambas is great! |
Gambas is great!</pre> |
||
Gambas is great! |
|||
==={{header|GW-BASIC}}=== |
|||
</pre> |
|||
{{works with|BASICA}} |
|||
{{works with|PC-BASIC|any}} |
|||
<syntaxhighlight lang="qbasic">10 FOR I = 1 TO 21 STEP 2 |
|||
20 PRINT I; |
|||
30 NEXT I</syntaxhighlight> |
|||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
Line 670: | Line 678: | ||
==={{header|Liberty BASIC}}=== |
==={{header|Liberty BASIC}}=== |
||
<syntaxhighlight lang="lb"> |
<syntaxhighlight lang="lb">for i = 2 to 8 step 2 |
||
for i = 2 to 8 step 2 |
|||
print i; ", "; |
print i; ", "; |
||
next i |
next i |
||
print "who do we appreciate?" |
print "who do we appreciate?" |
||
end</syntaxhighlight> |
|||
end |
|||
</syntaxhighlight> |
|||
==={{header|Microsoft Small Basic}}=== |
==={{header|Microsoft Small Basic}}=== |
||
<syntaxhighlight lang="microsoftsmallbasic"> |
<syntaxhighlight lang="microsoftsmallbasic">For i = 0 To 100 Step 2 |
||
For i = 0 To 100 Step 2 |
|||
TextWindow.WriteLine(i) |
TextWindow.WriteLine(i) |
||
EndFor |
EndFor</syntaxhighlight> |
||
</syntaxhighlight> |
|||
==={{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}} |
|||
{{works with|Just BASIC}} |
|||
{{works with|Liberty BASIC}} |
|||
{{works with|Run BASIC}} |
|||
{{works with|Yabasic}} |
|||
<syntaxhighlight lang="qbasic">10 FOR I = 1 TO 21 STEP 2 |
|||
20 PRINT I; " "; |
|||
30 NEXT I |
|||
40 END</syntaxhighlight> |
|||
==={{header|MSX Basic}}=== |
|||
<syntaxhighlight lang="qbasic">10 FOR I = 1 TO 21 STEP 2 |
|||
20 PRINT I; |
|||
30 NEXT I</syntaxhighlight> |
|||
==={{header|NS-HUBASIC}}=== |
==={{header|NS-HUBASIC}}=== |
||
Line 689: | Line 715: | ||
20 PRINT I |
20 PRINT I |
||
30 NEXT</syntaxhighlight> |
30 NEXT</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 1 3 5 7 9 11 13 15 17 19 21</pre> |
|||
<pre> |
|||
1 3 5 7 9 11 13 15 17 19 21 |
|||
</pre> |
|||
==={{header|PureBasic}}=== |
==={{header|PureBasic}}=== |
||
Line 700: | Line 723: | ||
Next i</syntaxhighlight> |
Next i</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>-15 |
||
-15 |
|||
-10 |
-10 |
||
-5 |
-5 |
||
Line 709: | Line 731: | ||
15 |
15 |
||
20 |
20 |
||
25 |
25</pre> |
||
</pre> |
|||
Decrementing with step |
Decrementing with step |
||
Line 717: | Line 738: | ||
Next ; i is optional</syntaxhighlight> |
Next ; i is optional</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>10 |
||
10 |
|||
8 |
8 |
||
6 |
6 |
||
4 |
4 |
||
2 |
2 |
||
0</pre> |
|||
0 |
|||
</pre> |
|||
==={{header|QB64}}=== |
==={{header|QB64}}=== |
||
Line 733: | Line 752: | ||
{{out}} |
{{out}} |
||
A newline is inserted automatically after the Print statement |
A newline is inserted automatically after the Print statement |
||
<pre> |
<pre>0 |
||
0 |
|||
2 |
2 |
||
4 |
4 |
||
6 |
6 |
||
8 |
8 |
||
10 |
10</pre> |
||
</pre> |
|||
We can also decrement with stepping |
We can also decrement with stepping |
||
<syntaxhighlight lang="qbasic">For i% = 10 to 0 Step -2 |
<syntaxhighlight lang="qbasic">For i% = 10 to 0 Step -2 |
||
Print i% |
Print i% |
||
Next i |
Next i </syntaxhighlight> |
||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre>10 |
|||
<pre> |
|||
10 |
|||
8 |
8 |
||
6 |
6 |
||
4 |
4 |
||
2 |
2 |
||
9</pre> |
|||
9 |
|||
</pre> |
|||
==={{header|QBasic}}=== |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<syntaxhighlight lang="qbasic">FOR i = 1 TO 21 STEP 2 |
|||
PRINT i; |
|||
NEXT i</syntaxhighlight> |
|||
==={{header|Quite BASIC}}=== |
|||
<syntaxhighlight lang="qbasic">10 FOR I = 1 TO 21 STEP 2 |
|||
20 PRINT I; " "; |
|||
30 NEXT I</syntaxhighlight> |
|||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
Line 786: | Line 811: | ||
Disp i |
Disp i |
||
EndFor</syntaxhighlight> |
EndFor</syntaxhighlight> |
||
==={{Header|Tiny BASIC}}=== |
|||
<syntaxhighlight lang="qbasic"> REM TinyBasic does not have a for-loop construct. |
|||
REM Equivalent using conditional jump: |
|||
LET i = 1 |
|||
10 IF i > 21 THEN GOTO 20 |
|||
PRINT i |
|||
LET i = i + 2 |
|||
GOTO 10 |
|||
20 END</syntaxhighlight> |
|||
==={{header|True BASIC}}=== |
==={{header|True BASIC}}=== |
||
Line 795: | Line 831: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>1 3 5 7 9 11 13 15 17 19 21</pre> |
|||
<pre> |
|||
1 3 5 7 9 11 13 15 17 19 21 |
|||
</pre> |
|||
Since TrueBasic does not distinguish between integer or real values, we can increment using decimal values as well |
Since TrueBasic does not distinguish between integer or real values, we can increment using decimal values as well |
||
<syntaxhighlight lang="qbasic"> |
<syntaxhighlight lang="qbasic">FOR i = 1 TO 5 STEP .5 |
||
FOR i = 1 TO 5 STEP .5 |
|||
PRINT i |
PRINT i |
||
NEXT i |
NEXT i |
||
END</syntaxhighlight> |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre>1 |
||
1 |
|||
1.5 |
1.5 |
||
2 |
2 |
||
Line 816: | Line 847: | ||
4 |
4 |
||
4.5 |
4.5 |
||
5</pre> |
|||
5 |
|||
</pre> |
|||
==={{header|Visual Basic}}=== |
==={{header|Visual Basic}}=== |
||
Line 828: | Line 858: | ||
End Sub</syntaxhighlight> |
End Sub</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> 2 4 6 8 </pre> |
||
2 4 6 8 |
|||
</pre> |
|||
==={{header|Visual Basic .NET}}=== |
==={{header|Visual Basic .NET}}=== |
||
Line 844: | Line 872: | ||
End Module</syntaxhighlight> |
End Module</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2, 4, 6, 8, who do we appreciate?</pre> |
|||
<pre> |
|||
2, 4, 6, 8, who do we appreciate? |
|||
</pre> |
|||
{{works with|Visual Basic .NET|2011}} |
{{works with|Visual Basic .NET|2011}} |
||
Line 860: | Line 886: | ||
End Class</syntaxhighlight> |
End Class</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>2 4 6 8 </pre> |
||
2 4 6 8 |
|||
</pre> |
|||
==={{header|XBasic}}=== |
==={{header|XBasic}}=== |
||
{{works with|Windows XBasic}} |
{{works with|Windows XBasic}} |
||
<syntaxhighlight lang="xbasic"> |
<syntaxhighlight lang="xbasic">PROGRAM "forby" |
||
PROGRAM "forby" |
|||
DECLARE FUNCTION Entry() |
DECLARE FUNCTION Entry() |
||
Line 876: | Line 899: | ||
NEXT i% |
NEXT i% |
||
END FUNCTION |
END FUNCTION |
||
END PROGRAM |
END PROGRAM</syntaxhighlight> |
||
</syntaxhighlight> |
|||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |