Loops/Wrong ranges: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
imported>Thebeez
(Added uBasic/4tH version)
Line 726: Line 726:
Start equal stop equal zero: zero increment ------ 0 0 0 0 0 0 0 0 0 0</pre>
Start equal stop equal zero: zero increment ------ 0 0 0 0 0 0 0 0 0 0</pre>


==={{header|uBasic/4tH}}===
<syntaxhighlight lang="qbasic">Push -2, 2, 1, "Normal"
Push -2, 2, 0, "Zero increment"
Push -2, 2, -1, "Increments away from stop value"
Push -2, 2, 10, "First increment is beyond stop value"
Push 2, -2, 1, "Start more than stop: positive increment"
Push 2, 2, 1, "Start equal stop: positive increment"
Push 2, 2, -1, "Start equal stop: negative increment"
Push 2, 2, 0, "Start equal stop: zero increment"
Push 0, 0, 0, "Start equal stop equal zero: zero increment"

Do While Used()
Print "(";Show (Pop());")"
i = Pop() : e = Pop () : s = Pop() : y = 0
Print "FOR X=";s;" TO ";e;" STEP ";i

For x = s To e Step i : Print x;" "; : While Set (y, y+1) < 10 : Next

Print Show(Iif (y < 10, Iif (y = 0, "None", ""), ".. infinite")) : Print
Loop</syntaxhighlight>
{{Out}}
<pre>(Start equal stop equal zero: zero increment)
FOR X=0 TO 0 STEP 0
0 0 0 0 0 0 0 0 0 0 .. infinite

(Start equal stop: zero increment)
FOR X=2 TO 2 STEP 0
2 2 2 2 2 2 2 2 2 2 .. infinite

(Start equal stop: negative increment)
FOR X=2 TO 2 STEP -1
2

(Start equal stop: positive increment)
FOR X=2 TO 2 STEP 1
2

(Start more than stop: positive increment)
FOR X=2 TO -2 STEP 1
None

(First increment is beyond stop value)
FOR X=-2 TO 2 STEP 10
-2

(Increments away from stop value)
FOR X=-2 TO 2 STEP -1
None

(Zero increment)
FOR X=-2 TO 2 STEP 0
-2 -2 -2 -2 -2 -2 -2 -2 -2 -2 .. infinite

(Normal)
FOR X=-2 TO 2 STEP 1
-2 -1 0 1 2


0 OK, 0:718 </pre>
==={{header|Yabasic}}===
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}