Loops/Continue: Difference between revisions

no edit summary
(Added Bracmat example)
No edit summary
Line 137:
end for_i
end.</lang>
 
=={{header|Applesoft BASIC}}==
<lang ApplesoftBasic> 10 FOR I = 1 TO 10
20 PRINT I;
30 IF I - INT (I / 5) * 5 = 0 THEN PRINT : GOTO 50"CONTINUE
40 PRINT ", ";
50 NEXT</lang>
 
=={{header|AutoHotkey}}==
Line 164 ⟶ 157:
}</lang>
 
=={{header|BBC BASIC}}==
 
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic> 10 FOR I = 1 TO 10
20 PRINT I;
30 IF I - INT (I / 5) * 5 = 0 THEN PRINT : GOTO 50"CONTINUE
40 PRINT ", ";
50 NEXT</lang>
 
==={{header|BBC BASIC}}===
BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.
<lang bbcbasic> FOR i% = 1 TO 10
Line 170 ⟶ 172:
IF i% MOD 5 = 0 PRINT ELSE PRINT ", ";
NEXT</lang>
 
==={{header|Commodore BASIC}}===
Commodore BASIC also doesn't have a 'continue' statement. An extra PRINT statement is executed with a condition. However, Commodore BASIC doesn't have a modulo (remainder) operator, so value of I/5 is check against INT(I/5). If they are the same, the remainder is zero. In the example below, the remainder is checked twice to avoid the use of a GOTO statement.
<lang qbasic>10 FOR I = 1 to 10
20 PRINT I;
30 IF INT(I/5) = I/5 THEN PRINT
40 IF INT(I/5) <> I/5 THEN PRINT ", ";
50 NEXT</lang>
In this second example, a GOTO statement is used to simulate 'CONTINUE'
<lang qbasic>10 FOR I = 1 to 10
20 PRINT I;
30 IF INT(I/5) = I/5 THEN PRINT : GOTO 50
40 PRINT ", ";
50 NEXT</lang>
 
==={{header|FreeBASIC}}===
<lang freebasic>' FB 1.05.0 Win64
For i As Integer = 1 To 10
Print Str(i);
If i Mod 5 = 0 Then
Print
Continue For
End If
Print ", ";
Next
 
Print
Sleep</lang>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
==={{header|Liberty BASIC}}===
<lang lb>
for i =1 to 10
if i mod 5 <>0 then print i; ", "; else print i
next i
end
</lang>
 
==={{header|PureBasic}}===
<lang purebasic>OpenConsole()
 
For i.i = 1 To 10
Print(Str(i))
If i % 5 = 0
PrintN("")
Continue
EndIf
Print(",")
Next
 
Repeat: Until Inkey() <> ""</lang>
 
==={{header|Run BASIC}}===
<lang runbasic>for i = 1 to 10
if i mod 5 <> 0 then print i;", "; else print i
next i</lang>
 
==={{header|TI-89 BASIC}}===
<lang ti-89>count()
Prgm
""→s
For i,1,10
s&string(i)→s
If mod(i,5)=0 Then
Disp s
""→s
Cycle
EndIf
s&", "→s
EndFor
EndPrgm</lang>
 
Ti-89 lacks support for multi-argument display command or controlling the print position so that one can print several data on the same line. The display command (Disp) only accepts one argument and prints it on a single line (causing a line a feed at the end, so that the next Disp command will print in the next line). The solution is appending data to a string (s), using the concatenator operator (&), by converting numbers to strings, and then printing the string at the end of the line.
 
==={{header|Visual Basic .NET}}===
<lang vbnet>For i = 1 To 10
Console.Write(i)
If i Mod 5 = 0 Then
Console.WriteLine()
Else
Console.Write(", ")
End If
Next</lang>
 
=={{header|bc}}==
Line 710 ⟶ 800:
 
This sort of scheme facilitates a compact way of printing a table with a heading, where the WRITE statement simply pours forth the data and relies on something like FORMAT("heading",/,(complex details for one line)) - thus printing the table line-by-line with only the first line having the heading, a saving on having a write and format statement pair for the heading and a second pair for the table body.
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
For i As Integer = 1 To 10
Print Str(i);
If i Mod 5 = 0 Then
Print
Continue For
End If
Print ", ";
Next
 
Print
Sleep</lang>
 
{{out}}
<pre>
1, 2, 3, 4, 5
6, 7, 8, 9, 10
</pre>
 
=={{header|GAP}}==
Line 945 ⟶ 1,015:
'Hello, World!' // never gets executed
^}</lang>
 
=={{header|Liberty BASIC}}==
<lang lb>
for i =1 to 10
if i mod 5 <>0 then print i; ", "; else print i
next i
end
</lang>
 
=={{header|Lingo}}==
Line 1,336 ⟶ 1,398:
Write-Host -NoNewline ", "
}</lang>
 
=={{header|PureBasic}}==
<lang purebasic>OpenConsole()
 
For i.i = 1 To 10
Print(Str(i))
If i % 5 = 0
PrintN("")
Continue
EndIf
Print(",")
Next
 
Repeat: Until Inkey() <> ""</lang>
 
=={{header|Python}}==
Line 1,486 ⟶ 1,534:
Without meeting the criteria (showing loop continuation), this task could be written as:
<lang ruby>(1..10).each_slice(5){|ar| puts ar.join(", ")}</lang>
 
=={{header|Run BASIC}}==
<lang runbasic>for i = 1 to 10
if i mod 5 <> 0 then print i;", "; else print i
next i</lang>
 
=={{header|Rust}}==
Line 1,628 ⟶ 1,671:
puts -nonewline ", "
}</lang>
 
=={{header|TI-89 BASIC}}==
<lang ti-89>count()
Prgm
""→s
For i,1,10
s&string(i)→s
If mod(i,5)=0 Then
Disp s
""→s
Cycle
EndIf
s&", "→s
EndFor
EndPrgm</lang>
 
Ti-89 lacks support for multi-argument display command or controlling the print position so that one can print several data on the same line. The display command (Disp) only accepts one argument and prints it on a single line (causing a line a feed at the end, so that the next Disp command will print in the next line). The solution is appending data to a string (s), using the concatenator operator (&), by converting numbers to strings, and then printing the string at the end of the line.
 
=={{header|TUSCRIPT}}==
Line 1,710 ⟶ 1,736:
}</lang>
 
=={{header|Visual Basic .NET}}==
<lang vbnet>For i = 1 To 10
Console.Write(i)
If i Mod 5 = 0 Then
Console.WriteLine()
Else
Console.Write(", ")
End If
Next</lang>
 
=={{header|XPL0}}==
Anonymous user