
Show the following output using one loop.
1, 2, 3, 4, 56, 7, 8, 9, 10
Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it.
L(i) 1..10 I i % 5 == 0 print(i) L.continue print(i, end' ‘, ’)
1, 2, 3, 4, 56, 7, 8, 9, 10
* Loops/Continue 12/08/2015LOOPCONT CSECT USING LOOPCONT,R12 LR R12,R15BEGIN LA R8,0 SR R5,R5 LA R6,1 LA R7,10LOOPI BXH R5,R6,ELOOPI for i=1 to 10 LA R3,MVC(R8) XDECO R5,XDEC MVC 0(4,R3),XDEC+8 LA R8,4(R8) LR R10,R5 LA R1,5 SRDA R10,32 DR R10,R1 LTR R10,R10 BNZ COMMA XPRNT MVC,80 LA R8,0 B NEXTICOMMA LA R3,MVC(R8) MVC 0(2,R3),=C', ' LA R8,2(R8)NEXTI B LOOPI next iELOOPI XR R15,R15 BR R14MVC DC CL80' 'XDEC DS CL16 YREGS END LOOPCONT
1, 2, 3, 4, 5 6, 7, 8, 9, 10
Ada doesn't have a continue statement, so we have to use a goto statement. The previous submitter said continue is not needed. In this example it is indeed not needed,but that is not always the case. An example is a loop where a number of interdependent conditions are checked before executing the main body of the loop. Without a continue statement (or goto), one ends up with nested statements with the main body to the far right of the page.
B.N. You should always try to avoid using a goto,but if you really must, it's there in Ada.
P.S. it is often simplest to place the label on top of theloop, as in real life the need occurs when reading input, so there is no range condition in the loop and we canforgo the null statement.
withAda.Text_IO;useAda.Text_IO;procedureLoop_ContinueisbeginforIin1..10loopPut(Integer'Image(I));ifI=5orI=10thenNew_Line;gotoContinue;endif;Put(",");<<Continue>>--Ada 2012 no longer requires a statement after the labelendloop;endLoop_Continue;
N. This is a more true-to-Ada strategy for 'continue' comprising of an outer iteration loop and an inner labeled single-pass loop. This is a safer strategy than using goto which could be problematic when dealing with complex nested loops.
withAda.Text_IO;useAda.Text_IO;procedureLoop_ContinueisbeginPrint_All:forIin1..10loopPrint_Element:loopPut(Integer'Image(I));ifI=5orI=10thenNew_Line;exitPrint_Element;endif;Put(",");exitPrint_Element;endloopPrint_Element;endloopPrint_All;endLoop_Continue;
Agena doesn't have a continue statement, conditional statements can be used instead.
for i to 10 do write( i ); if i % 5 = 0 then write( "\n" ) else write( ", " ) fiod
foreach i 1..10 { print (i) if ((i % 5) == 0) { println() continue } print (", ")}begininteger i;for i:=1step 1until 10dobegin outinteger(i);if i=(idiv 5)*5then outimageelse outstring(", ")endend+1 , +2 , +3 , +4 , +5 +6 , +7 , +8 , +9 , +10
ALGOL 68 has no continue reserved word, nor does it need one. The continue reserved word is only syntactic sugar for operations that can be achieved without it as in the following example:
FOR i FROM 1 TO 10 DO print ((i, IF i MOD 5 = 0 THEN new line ELSE "," FI ))OD
+1, +2, +3, +4, +5 +6, +7, +8, +9, +10
Algol W doesn't have a continue statement - conditional statements can be used instead.
begin i_w := 1; s_w := 0; % set output format % for i := 1 until 10 do begin writeon( i ); if i rem 5 = 0 then write() else writeon( ", " ) end for_iend.
settableto{return}repeatwithifrom1to10ifi<5or(i≥6andi<10)thensetendoftabletoi&", "elseifi=5ori=10thensetendoftabletoi&returnendifendrepeatreturntableasstring
"1, 2, 3, 4, 56, 7, 8, 9, 10"
loop1..10'i[printsiif0=i%5[print""continue]prints","]
1, 2, 3, 4, 56, 7, 8, 9, 10
Asymptote's control structures are similar to those in C/C++
for(inti=1;i<=10;++i){write(i,suffix=none);if(i%5==0){write("");continue;}else{write(", ",suffix=none);}}
Loop,10{Delimiter:=(A_Index=5)||(A_Index=10)?"`n":", "Index.=A_Index.Delimiter}MsgBox%Index%
BEGIN{for(i=1;i<=10;i++){printf("%d",i)if(i%5==0){printcontinue}printf(", ")}}
importballerina/io;publicfunctionmain(){foreachintiin1...10{io:print(i);ifi%5==0{io:println();continue;}io:print(", ");}}
1, 2, 3, 4, 56, 7, 8, 9, 10
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
for i = 1 to 10print string(i);if i mod 5 = 0 thenprintcontinue forend ifprint ", ";nextprintend
BBC BASIC doesn't have a 'continue' statement so the remainder of the loop must be made conditional.
FORi%=1TO10PRINT;i%;IFi%MOD5=0PRINTELSEPRINT", ";NEXT
Commodore BASIC also doesn't have a 'continue' statement. In this example, a GOTO statement is used to simulate 'CONTINUE'. 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.
10FORI=1to1020PRINTI;30IFINT(I/5)=I/5THENPRINT:GOTO5040PRINT", ";50NEXT
' FB 1.05.0 Win64ForiAsInteger=1To10PrintStr(i);IfiMod5=0ThenPrintContinueForEndIfPrint", ";NextPrintSleep
1, 2, 3, 4, 56, 7, 8, 9, 10
100 FOR I=1 TO 10110 PRINT STR$(I);120 IF MOD(I,5)=0 THEN130 PRINT 140 ELSE150 PRINT ", ";160 END IF170 NEXT
for i =1 to 10 if i mod 5 <>0 then print i; ", "; else print inext iend
uses consoleint ifor i = 1 to 10print str(i);if i mod 5 = 0 thenprintlcontinue forend ifprint ", ";nextprintl cr "Enter ..."waitkey
OpenConsole()Fori.i=1To10Print(Str(i))Ifi%5=0PrintN("")ContinueEndIfPrint(",")NextRepeat:UntilInkey()<>""
FORi=1TO10PRINTSTR$(i);IF(iMOD5)THENPRINT", ";ELSEPRINTNEXTiPRINTEND
Dim i As IntegerFor i = 1 To 10 Print LTrim$(Str$(i)); If i Mod 5 = 0 Then Print _Continue End If Print ", ";Next
for i = 1 to 10 if i mod 5 <> 0 then print i;", "; else print inext i
This probably isn't the most idiomatic way to produce the specified output—but it does illustrate ZX81 BASIC's equivalent ofif <condition> continue, which isIF <condition> THEN NEXT <loop-control variable>.
10 FOR I=1 TO 1020 PRINT I;30 IF I/5=INT (I/5) THEN PRINT40 IF I/5=INT (I/5) THEN NEXT I50 PRINT ", ";60 NEXT I
count()Prgm ""→s For i,1,10 s&string(i)→s If mod(i,5)=0 Then Disp s ""→s Cycle EndIf s&", "→s EndForEndPrgm
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.
FORi=1TO10PRINTSTR$(i);IFREMAINDER(i,5)=0THENPRINTELSE!NoexisteelcomandoCONTINUEPRINT", ";ENDIFNEXTiPRINTEND
OPTIONEXPLICITDIMiASINTEGERCLSFORi=1TO10PRINTSTR$(i);IF(iMOD5)THENPRINT",";ELSEPRINTNEXTiEND
Fori=1To10Console.Write(i)IfiMod5=0ThenConsole.WriteLine()ElseConsole.Write(", ")EndIfNext
Requires abc with theprint andcontinue statements. POSIX bc has not these statements.
for(i=1; i<=10; i++){print iif(i%5){print", "continue}print"\n"}quit
In BCPL, thecontinue statement is namedloop.
get "libhdr"let start() be for i = 1 to 10 $( writen(i) if i rem 5 = 0 $( wrch('*N') loop $) writes(", ") $)1, 2, 3, 4, 56, 7, 8, 9, 10
Befunge outputs numbers with a space after them, so the formatting is slightly off in this version.
1>:56+\`#v_@+v%5:.:<1>#v_55+,v^<>" ,",,v^<
This version outputs a 'backspace' ASCII character to try to correct the format, but it may or may not work depending on if the character is accounted for by the output
1>:56+\`#v_@+v5:,8.:<1>%#v_55+,v^<>" ,",v^,<
Bracmat has no continue statement.
( 0:?i& whl ' ( 1+!i:~>10:?i & put $ ( str $ ( !i (mod$(!i.5):0&\n|", ") ) ) ));
for(inti=1;i<=10;i++){printf("%d",i);if(i%5==0){printf("\n");continue;}printf(", ");}
usingSystem;classProgram{staticvoidMain(string[]args){for(inti=1;i<=10;i++){Console.Write(i);if(i%5==0){Console.WriteLine();continue;}Console.Write(", ");}}}
for(inti=1;i<=10;i++){cout<<i;if(i%5==0){cout<<endl;continue;}cout<<", ";}
for (int i = 1; i <= 10; i++){ io::print(i); if (i % 5 == 0) { io::printn(); continue; } io::print(", ");}foriin1..10{write(i);ifi%5==0then{writeln();continue;}write(", ");}
LOOP keyword is used here instead ofcontinue.
Works as is with Harbour 3.0.0 (Rev. 16951)
FOR i := 1 TO 10 ?? iIF i % 5 == 0 ?LOOPENDIF ??", "NEXT
Clojure doesn't have a continue keyword. It has a recur keyword, although I prefer to work with ranges in this case.
(doseq[n(range111)](printn)(if(zero?(remn5))(println)(print", ")))
To address the task, however, here's an example loop/recur:
(loop[xs(range111)](when-let[x(firstxs)](printx)(if(zero?(remx5))(println)(print", "))(recur(restxs))))
IDENTIFICATIONDIVISION.PROGRAM-ID.loop-continue.DATADIVISION.WORKING-STORAGESECTION.01iPIC 99.PROCEDUREDIVISION.PERFORMVARYINGiFROM1BY1UNTIL10<iDISPLAYiWITHNOADVANCINGIFFUNCTIONMOD(i,5)=0DISPLAYSPACEEXITPERFORMCYCLEEND-IFDISPLAY", "WITHNOADVANCINGEND-PERFORMGOBACK.
Note: COBOL does have aCONTINUE verb, but this is a no-operation statement used inIF andEVALUATE statements.
Remove the leading space from the line break tag.
<cfscript>for(i=1;i<=10;i++){writeOutput(i);if(0==i%5){writeOutput("< br />");continue;}writeOutput(",");}</cfscript>
Common Lisp doesn't have a continue keyword, but thedo iteration construct does use an implicittagbody, so it's easy togo to any label. Four solutions follow. The first pushes the conditional (whether to print a comma and a space or a newline) into the format string. The second uses the implicittagbody andgo. The third is a do loop with conditionals outside of the output functions.
(do((i1(1+i)))((>i10))(formatt"~a~:[, ~;~%~]"i(zerop(modi5))))(do((i1(1+i)))((>i10))(writei)(when(zerop(modi5))(terpri)(goend))(write-string", ")end)(do((i1(1+i)))((>i10))(writei)(if(zerop(modi5))(terpri)(write-string", ")))
These use theloop iteration form, which does not contain an implicit tagbody (though one could be explicitly included). The first uses an explicit condition to omit the rest of the loop; the second usesblock/return-from to obtain the effect of skipping the rest of the code in theblock which makes up the entire loop body.
(loopforifrom1to10do(writei)if(zerop(modi5))do(terpri)elsedo(write-string", "))(loopforifrom1to10do(blockcontinue(writei)(when(zerop(modi5))(terpri)(return-fromcontinue))(write-string", ")))
include "cowgol.coh";var n: uint8 := 0;while n < 10 loop n := n + 1; print_i8(n); if n % 5 == 0 then print_nl(); continue; end if; print(", ");end loop;1, 2, 3, 4, 56, 7, 8, 9, 10
importstd.stdio;voidmain(){foreach(i;1..11){write(i);if(i%5==0){writeln();continue;}write(", ");}}
1, 2, 3, 4, 56, 7, 8, 9, 10
importstd.stdio;voidmain(){foreach(i;1..11)i%5?writef("%s, ",i):writeln(i);}
The four commands# n J M are special toOpenBSD dc. The# command starts a comment. Then command prints a number without a newline.
1 si# i = 1[2Q]sA# A = code to break loop[[, ]P 1J]sB# B = code to print comma, continue loop[ li n# print i li 5 % 0 !=B# call B if i % 5 []P # print newline M# mark from calling B li 1 + si# i += 1 li 10!<C# continue loop if 10 >= i]sC li 10!<C# enter loop if 10 >= i
This program usesJ andM to force the next iteration of a loop. ThenJ command breaksn levels of brackets (likenQ does so), but then skips to the nextM command. One can placeM at the end of the iteration.
programDoLoop(output);vari:integer;beginfori:=1to10dobeginwrite(i);ifimod5=0thenbeginwriteln;continue;end;write(', ');end;end.
1, 2, 3, 4, 56, 7, 8, 9, 10
vari:Integer;fori:=1to10dobeginPrint(i);ifimod5=0thenbeginPrintLn('');continue;end;Print(', ');end;
for i in 1..10 { print(i, terminator: "") if i % 5 == 0 { print() continue } print(", ", terminator: "")}1, 2, 3, 4, 56, 7, 8, 9, 10
open monad io loop n = if n > 10 then do return () else do putStr (show n) putStr f loop (n + 1) where f | n % 5 == 0 = "\r\n" | else = ", "_ = loop 1 ::: IO
open monad io loop [] = return ()loop (x::xs) = do putStr (show x) putStr f loop xs where f | x % 5 == 0 = "\r\n" | else = ", " _ = loop [1..10] ::: IO
This version is more generic and can work for any given range of values.
defmoduleLoopsdodefcontinuedoEnum.each(1..10,fni->IO.writeiIO.writeifrem(i,5)==0,do:"\n",else:", "end)endendLoops.continue
1, 2, 3, 4, 56, 7, 8, 9, 10
for int i = 1; i <= 10; ++i write(i) if i % 5 == 0 writeLine() continue end write(", ")end1, 2, 3, 4, 56, 7, 8, 9, 10
%% Implemented by Arjun Sunel-module(continue).-export([main/0,for_loop/1]).main()->for_loop(1).for_loop(N)whenN/=5,N<10->io:format("~p, ",[N]),for_loop(N+1);for_loop(N)whenN>=10->ifN=:=10->io:format("~p\n",[N])end;for_loop(N)->ifN=:=5->io:format("~p\n",[N]),for_loop(N+1)end.
1, 2, 3, 4, 56, 7, 8, 9, 10ok
FOR I=1 TO 10 DO PRINT(I;CHR$(29);) ! printing a numeric value leaves a blank after it ! chr$(29) delete it..... IF I MOD 5=0 THEN PRINT CONTINUE FOR END IF PRINT(",";)END FORPRINTinclude std\console.e --only for any_key to make running command window easier on windowsfor i = 1 to 10 do if remainder(i,5) = 0 then printf(1, "%d\n", i) else printf(1,"%d, ", i) continue end ifend forany_key()
Version without newline after 10 below.
include std\console.e --only for any_key to make running command window easier on windowsfor i = 1 to 10 do if remainder(i,5) = 0 then switch i do case 10 then printf(1,"%d ",i) break --new to euphoria 4.0.0+ case else printf(1,"%d\n", i) end switch else printf(1,"%d, ", i) continue --new to euphoria 4.0.0+ end ifend forany_key()
continue is a reserved word, but it has no function. In any case, it is not needed to complete this task.
foriin1..10doprintf"%d"iifi%5=0thenprintf"\n"elseprintf", "
letfNg=quibble(Seq.initInfinite(funn->if(n+1)%5=0||(n+1)=List.lengthgthen"\n"else", "))gfN[1]|>Seq.iter(fun(n,g)->printf"%d%s"ng)fN[1..9]|>Seq.iter(fun(n,g)->printf"%d%s"ng)fN[1..10]|>Seq.iter(fun(n,g)->printf"%d%s"ng)fN[1..11]|>Seq.iter(fun(n,g)->printf"%d%s"ng)
11, 2, 3, 4, 56, 7, 8, 91, 2, 3, 4, 56, 7, 8, 9, 101, 2, 3, 4, 56, 7, 8, 9, 1011
There is no built-incontinue in Factor.
1 10[a,b][[number>stringwrite][5mod0="\n"", "?write]bi]each
While and for loops supportcontinue to jump back to begin the next iteration of the loop.
class LoopsContinue{ public static Void main () { for (Int i := 1; i <= 10; ++i) { Env.cur.out.print (i) if (i % 5 == 0) { Env.cur.out.printLine ("") continue } Env.cur.out.print (", ") } Env.cur.out.printLine ("") }}Although this code solves the task, there is no portable equivalent to "continue" for either DO-LOOPs or BEGIN loops.
:main111doidup1r.5mod0=ifcrelse[char],emitspacethenloop;
doi=1,10write(*,'(I0)',advance='no')iif(mod(i,5)==0)then write(*,*)cycle end if write(*,'(A)',advance='no')', 'end do
CWARNING:Thisprogram isnotvalidANSIFORTRAN77code.ItusesConenonstandardcharacteronthelinelabelled5001.ManyF77Ccompilersshouldbeokaywithit,butitis*not*standard.CCItisalsoworthnotingthatFORTRAN77usesthecommandCONTINUE,Cbutnotinthesemantic,loopingsenseoftheword.InFORTRAN,CCONTINUEmeans"do absolutely nothing."Itisaplaceholder.IfCanything,itmeans"continue to the next line."CCPythondoesthesamethingwith`pass`;CanditsfamilyofClanguages,with`{/*donothing*/}`.Write CONTINUEwhenyouneedCtowritesomethingbuthavenothingtowrite.CCThispageonRosettaCodeisaboutaverydifferent"continue"Cstatementthattellsalooptogobacktothebeginning.InCFORTRAN,weuse(youguessedit!) a GOTO to accomplish this.PROGRAMCONTINUELOOPINTEGERIDO10I=1,10CIsitfiveorten?IF(MOD(I,5).EQ.0)THENCIfitis,writeanewlineandnocomma.WRITE(*,5000)ICContinuetheloop;thatis,skiptotheendoftheloop.GOTO10ENDIFCWriteIwithacommaandnonewline.WRITE(*,5001)ICAgain,inthiscase,CONTINUE iscompletelyunrelatedtotheCsemantic,loopingsenseoftheword.10CONTINUE STOPCThiswillprintanintegerandanewline(nocomma).5000FORMAT(I3)CStandardFORTRAN77iscompletelyincapableofcompletingaCWRITEstatementwithoutprintinganewline.IfyouwanttoprintCfiveintegersinstandardcode,youhavetodosomethinglikeCthis:CCFORMAT(I3,',',I3,',',I3,',',I3,',',I3)CCWriting`1,2,3,4,5`andthen`6,7,8,9,10`tothatformatCwouldproducethefollowingtwolines:CC1,2,3,4,5C6,7,8,9,10CCHowever,thiscodeexiststodemonstratecontinuingaFORTRAN77Cloopand nottodemonstratehowtogetarounditsrigidityaboutCnewlines.CCThedollarsignattheendoftheformat isanonstandardCcharacter.Ittellsthecompilernottoprintanewline.IfyouCareactuallyusingFORTRAN77,youshouldfigureoutwhatyourCparticularcompileraccepts.IfyouareactuallyusingFortranC90orlater,youshouldreplacethislinewiththecommentedClinethatfollowsit.5001FORMAT(I3,',',$)C5001FORMAT(I3,',',ADVANCE='NO')END
For historical reasons, 6 is often the default unit number for standard output.
WRITE(6,1)(I,I=1,10)1FORMAT(4(1X,I0,","),1X,I0)END
Here the break and continuation comes through the workings of the FORMAT interpreter. The feature 4(etc) means four repetitions of the format items within the brackets, and as each datum from the WRITE statement arrives, it is aligned with the next format item that can receive a datum, the I-format specifier (here I0, which means an integer of only as many digits as are needed for the value) and until such a reciever is encountered, intervening format items are acted upon - 1X means "one space", and the quotes surround a text literal. Accordingly, the first datum generates a space, a one-digit value, and a comma, as does the second and so on. When the sixth datum is received, the end of the format statement has been reached, and the convention is to write the current line and start a new line of output, and further, go back in the FORMAT specification to the first-encountered open-bracket symbol (the rightmost) which in this case is not the beginning of the FORMAT statement but the one that has a repetition count of four in front of it, and, resume interpretation. When the last datum has been accepted, naturally, the line is printed.
An alternative might be FORMAT (4(I2,","),I2) but that would generate
1, 2, 3, 4, 56, 7, 8, 9,10
Alternatively, FORMAT (4(I2,","),I2,/,4(I2,","),I3) would do the trick but there would no longer be the loop, break, continue aspect to the interpretation of the FORMAT statement, merely a grinding through a list.
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.
include "NSLog.incl"long numfor num = 1 to 10 if ( num mod 5 ) NSLog(@"%ld, \b",num) else NSLog(@"%ld",num) end ifnextHandleEvents
Click this link to run this code
PublicSubMain()DimsiCountAsShortForsiCount=1To10PrintsiCount;IfsiCount<>5AndsiCount<>10ThenPrint",";IfsiCount=5ThenPrintgb.NewLine;NextEnd
Output:
1,2,3,4,56,7,8,9,10
foriin[1..11]doifRemInt(i,5)=0thenPrint(i,"\n");continue;fi;Print(i,", ");od;# 1, 2, 3, 4, 5# 6, 7, 8, 9, 10
extendsMainLoopfunc_process(_delta:float)->bool:foriinrange(1,11):ifi%5==0:print(i)continueprintraw(i,", ")returntrue# Exit
for(i = 1; i <= 10; i += 1) { show_message(string(i)) i += 1 if(i <= 10) continue }packagemainimport"fmt"funcmain(){fori:=1;i<=10;i++{fmt.Printf("%d",i)ifi%5==0{fmt.Printf("\n")continue}fmt.Printf(", ")}}
1, 2, 3, 4, 56, 7, 8, 9, 10
11,1>{.5%", "n if}/:n;1, 2, 3, 4, 56, 7, 8, 9, 10
for(iin1..10){printiif(i%5==0){println()continue}print', '}
As a functional language, it is not idiomatic to have true loops - recursion is used instead. Below is one of many possible implementations of the task. The below code uses a guard (| symbol) to compose functions differently for the two alternative output paths, instead of using continue like in an imperative language.
importControl.Monad(forM)main=forM[1..10]outwhereoutx|x`mod`5==0=printx|otherwise=(putStr.(++", ").show)x
for(iin1...11){Sys.print(i);if(i%5==0){Sys.print('\n');continue;}Sys.print(', ');}
DO i = 1, 10 IF( MOD(i, 5) == 1 ) THEN WRITE(Format="i3") i ELSE WRITE(APPend, Format=" ',', i3 ") i ENDIFENDDO
The following code demonstrates the use of 'next' (the reserved word for 'continue'):
proceduremain()everywrites(x:=1to10)do{ifx%5=0then{write()next}writes(", ")}end
However, the output sequence can be written without 'next' and far more succinctly as:
everywrites(x:=1to10,ifx%5=0then"\n"else", ")
for(i,1,10,write(i)if(i%5==0,writeln();continue)write(" ,"))
J is array-oriented, so there is very little need for loops. For example, one could satisfy this task this way:
_2}."1'lq<, >'8!:2>:i.25
J does support loops for those times they can't be avoided (just like many languages support gotos for those time they can't be avoided).
3 : 0]10z=.''for_i.1+i.ydo.z=.z,":iif.0=5|ido.z1!:2]2z=.''continue.end.z=.z,', 'end.i.00)
Though it's rare to see J code like this.
for (i = 1; i < 11; i++) { print i println and continue if i % 5 == 0 print ", "}fn main() { for i in 1..11 { if i % 5 == 0 { println("{}", i) continue } print("{}, ", i) }}for(inti=1;i<=10;i++){System.out.print(i);if(i%5==0){System.out.println();continue;}System.out.print(", ");}
Using theprint() function fromRhino orSpiderMonkey.
varoutput="";for(vari=1;i<=10;i++){output+=i;if(i%5==0){print(output);output="";continue;}output+=", ";}
Stepping back from any assumption that repetitive patterns of computation necessarily entail 'loops', and using a functional idiom of JavaScript, we can make the value of one or more subexpressions in areduce() fold conditional on any special cases that we define.
For example:
functionrng(n){returnn?rng(n-1).concat(n):[];}console.log(rng(10).reduce(function(a,x){returna+x.toString()+(x%5?', ':'\n');},''));
Output:
1,2,3,4,56,7,8,9,10
jq does not have a "continue" statement. In jq 1.4, the simplest way to accomplish the given task is probably as follows:
reduce range(1;11) as $i (""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))/* Loop/continue in jsish */for(vari=1;i<=10;i++){printf("%d",i);if(i%5==0){printf("\n");continue;}printf(", ");}
prompt$ jsish loop-continue.jsi1, 2, 3, 4, 56, 7, 8, 9, 10
foriin1:10print(i)ifi%5==0println()continueendprint(", ")end
1, 2, 3, 4, 56, 7, 8, 9, 10
// version 1.1.2funmain(args:Array<String>){for(iin1..10){if(i%5==0){println(i)continue}print("$i, ")}}
1, 2, 3, 4, 56, 7, 8, 9, 10
{defloops_continue{lambda{:i}{if{>:i10}then(endofloop)else{if{=:i6}then{br}:ielse:i}{if{=:i10}then.else,}{loops_continue{+:i1}}}}}->loops_continue{loops_continue0}->0,1,2,3,4,5,6,7,8,9,10.(endofloop)
$i = 0while($i < 10) {$i += 1if($i % 5 === 0) {fn.println($i)con.continue}fn.print($i\,\s)}1, 2, 3, 4, 56, 7, 8, 9, 10
for i of 10 { write i if i div 5 { writeln(); next } write ", "}loop(10)=>{^loop_countloop_count%5?', '|'\r'loop_count<100?loop_continue'Hello, World!'// never gets executed^}
data:i is numbern is numberprocedure:for i from 1 to 11 step 1 do display i modulo i by 5 in n if n is equal to 0 then display lf continue end if display ", "repeat
1, 2, 3, 4, 56, 7, 8, 9, 10
str = ""repeat with i = 1 to 10 put i after str if i mod 5 = 0 then put RETURN after str next repeat end if put ", " after strend repeatput str
1.to 10 do { i : INTEGER; i.print; (i % 5 = 0).if { '\n'.print; } else { ','.print; };};repeat with n = 1 to 10 put n if n is 5 then put return if n < 10 and n is not 5 then put "," end repeat
fori=1,10doio.write(i)ifi%5==0thenio.write("\n")elseio.write(", ")endend
or
fori=1,10doio.write(i)ifi%5==0thenio.write("\n")gotocontinueendio.write(", ")::continue::end
Module Checkit { \\ A For {} loop For i=1 to 10 { Print i; if i mod 5 Else Print : continue Print ","; } Print i=11 \\ A For Next loop For i=1 to 10 Print i; if i mod 5 Else Print : continue Print ","; Next i Print i=11 \\ A for loop using a block and a Loop statement i=0 { i++ if i>10 then Exit loop Print i; if i mod 5 Else Print : continue Print ","; } Print i=11 \\ as above but end value for i=10 not 11 i=0 { i++ if i<10 then loop Print i; if i mod 5 Else Print : continue Print ","; } Print i=10 ' not 11 but 10}Checkitforifrom1to10doprintf("%d",i);ifirem(i,5)=0thenprintf("\n");nextendif;printf(", ")enddo:
This can also be done as follows, but without the use of "next".
forito10doprintf("%d%s",i,`if`(irem(i,5)=0,"\n",", "))enddo:
tmp="";For[i=1,i<=10,i++,tmp=tmp<>ToString[i];If[Mod[i,5]==0,tmp=tmp<>"\n";,tmp=tmp<>", ";];];Print[tmp]
Loops are considered slow in Matlab and Octave, it is preferable to vectorize the code.
disp([1:5;6:10])
or
disp(reshape([1:10],5,2)')
A non-vectorized version of the code is shown below in Octave
fori=1:10printf(' %2d',i);if(mod(i,5)==0)printf('\n');continueendend
/* There is no "continue" in Maxima, the easiest is using a "if" instead */block([s:""],fornthru10do(s:sconcat(s,n),ifmod(n,5)=0then(ldisp(s),s:"")else(s:sconcat(s,", "))))$
Using sprint and newline
forn:1thru10do(sprint(n),ifn=5thennewline())$
for i in 1 to 10 do( format "%" i if mod i 5 == 0 then ( format "\n" continue ) continue format ", ")
Insert non-formatted text here
Metafont has no acontinue (or similar) keyword. As theAda solution, we can complete the task just with conditional.
string s; s := "";for i = 1 step 1 until 10:if i mod 5 = 0: s := s & decimal i & char10;else: s := s & decimal i & ", "fi; endformessage s;end
Sincemessage append always a newline at the end, we need to build a string and output it at the end, instead of writing the output step by step.
Note:mod is not a built in; like TeX, "bare Metafont" is rather primitive, and normally a set of basic macros is preloaded to make it more usable; in particularmod is defined as
primarydef x mod y = (x-y*floor(x/y)) enddef;
Modula-3 defines the keywordRETURN as an exception, but when it is used with no arguments it works just likecontinue inC.
Note, however, thatRETURN only works inside a procedure or a function procedure; useEXIT otherwise.
Module code and imports are omitted.
FORi:=1TO10DOIO.PutInt(i);IFiMOD5=0THENIO.Put("\n");RETURN;END;IO.Put(", ");END;
s="";for iin[1..10] s+=tostr(i);if(i%5==0)player:tell(s); s="";continue;endif s+=", ";endfor
/** Loops/Continue in Neko Tectonics: nekoc loops-continue.neko neko loops-continue*/varindex=0;whileindex<10{index+=1;$print(index);if$not($istrue(index%5)){$print("\n");continue;}$print(", ");}
prompt$ nekoc loops-continue.nekoprompt$ neko loops-continue.n1, 2, 3, 4, 56, 7, 8, 9, 10
usingSystem;usingSystem.Console;usingNemerle.Imperative;moduleContinue{Main():void{foreach(iin[1..10]){Write(i);when(i%5==0){WriteLine();continue;}Write(", ");}}}
/* NetRexx */optionsreplaceformatcommentsjavacrossrefsavelogsymbolsnobinarysaysay'Loops/Continue'nul='\-'loopi_=1to10sayi_.right(2)||nulifi_//5=0thendosayiteratei_endsay', '||nulendi_
(for(i110)(printi)(if(=0(%i5))(println)(print", ")))
foriin1..10:ifimod5==0:echoicontinuestdout.writei,", "
10 FOR I=1 TO 1020 PRINT I;30 IF I-I/5*5=0 THEN PRINT :GOTO 50"CONTINUE40 PRINT ",";50 NEXT
for i in 1..10 {print -n $iif $i mod 5 == 0 {print ""continue}print -n ", "}Oberon-07/Oberon-2 do not have continue statements, as with many languages, conditional statements can be used instead.
MODULELoopsContinue;IMPORTOut;VARi:INTEGER;BEGINFORi:=1TO10DOOut.Int(i,0);IFi#5THENOut.String(", ")ELSEOut.LnENDENDENDLoopsContinue.
class Continue { function : Main(args : String[]) ~ Nil { for(i := 1; i <= 10; i += 1;) { if(i = 5) { "{$i}, "->PrintLine(); continue; }; "{$i}, "->Print(); }; }}There is no continue statement for for loops in OCaml, but it is possible to achieve the same effect with an exception.
#fori=1to10dotryprint_inti;if(imod5)=0thenraiseExit;print_string", "withExit->print_newline()done;;1,2,3,4,56,7,8,9,10-:unit=()
Though even if the continue statement does not exist, it is possible to add it with camlp4.
v="";fori=1:10v=sprintf("%s%d",v,i);if(mod(i,5)==0)disp(v)v="";continueendifv=sprintf("%s, ",v);endfor
: loopCont | i | 10 loop: i [ i dup print 5 mod ifZero: [ printcr continue ] "," . ] ;
We use continuation to break the execution of the inner body.
(letloop((i1))(when(less?i11)(call/cc(lambda(continue)(displayi)(when(zero?(modi5))(print)(continue#f))(display", ")))(loop(+i1))))
1, 2, 3, 4, 56, 7, 8, 9, 10
By using the "continue" feature of the for-loop, we bind C to a nullary procedure which, when invoked, immediately goes on to the next iteration of the loop.
for I in 1..10 continue:C do {System.print I} if I mod 5 == 0 then {System.printInfo "\n"} {C} end {System.printInfo ", "}endfor(n=1,10, print1(n); if(n%5 == 0, print();continue); print1(", "))See Delphi
beginforvari:=1to10dobeginWrite(i);ifimod5=0thenbeginWriteln;continueend;Write(', ');end;end.
1, 2, 3, 4, 56, 7, 8, 9, 10
foreach(1..10){print$_;if($_%5==0){print"\n";next;}print', ';}
It is also possible to use a goto statement to jump over the iterative code section for a particular loop:
foreach(1..10){print$_;if($_%5==0){print"\n";gotoMYLABEL;}print', ';MYLABEL:}
withjavascript_semanticsfori=1to10doprintf(1,"%d",i)ifremainder(i,5)=0thenprintf(1,"\n")continueendifprintf(1,", ")endfor
1, 2, 3, 4, 56, 7, 8, 9, 10
The following works just as well, with identical output
withjavascript_semanticsfori=1to10doprintf(1,"%d",i)ifremainder(i,5)=0thenprintf(1,"\n")elseprintf(1,", ")endifendfor
for($i=1;$i<=10;$i++){echo$i;if($i%5==0){echo"\n";continue;}echo', ';}
Picat doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.
main => foreach (I in 1..10) printf("%d", I), if (I mod 5 == 0) then nl else printf(", ") end, end.1, 2, 3, 4, 56, 7, 8, 9, 10
PicoLisp doesn't have an explicit 'continue' functionality. It can always be emulated with a conditional expression.
(for I 10 (print I) (if (=0 (% I 5)) (prinl) (prin ", ") ) )
intmain(){for(inti=1;i<=10;i++){write(sprintf("%d",i));if(i%5==0){write("\n");continue;}write(", ");}}
loop:do i = 1 to 10; put edit (i) (f(3)); if mod(i,5) = 0 then do; put skip; iterate loop; end; put edit (', ') (a);end;In Plain English, continue is spelledrepeat and is the only way to specify an end of a loop.
To run:Start up.Demonstrate continue.Wait for the escape key.Shut down.To demonstrate continue:If a counter is past 10, exit.Convert the counter to a string.Write the string on the console without advancing.If the counter is evenly divisible by 5, write "" on the console; repeat.Write ", " on the console without advancing.Repeat.
fori=1,10doio.write(i)ifi%5==0thenprint()continueendio.write(", ")end
1, 2, 3, 4, 56, 7, 8, 9, 10
lvars i;for i from 1 to 10 do printf(i, '%p'); if i rem 5 = 0 then printf('\n'); nextloop; endif; printf(', ')endfor;for($i=1;$i-le10;$i++){Write-Host-NoNewline$iif($i%5-eq0){Write-Hostcontinue}Write-Host-NoNewline", "}
Prolog doesn't have a continue statement. So I just use a conditional that ends the body of the predicate.
:-initialization(main).print_list(Min,Max):-Min<Max,write(Min),Min1isMin+1,(Minmod5=:=0->nl;write(',')),print_list(Min1,Max).print_list(Max,Max):-write(Max),nl.main:-print_list(1,10).
1,2,3,4,56,7,8,9,10
foriinrange(1,11):ifi%5==0:print(i)continueprint(i,end=', ')
10 times [ i^ 1+ dup echo 5 mod 0 = iff cr done say ", " ]
for(iin1:10){cat(i)if(i%%5==0){cat("\n")next}cat(", ")}
It is possible to skip loop iterations in Racket, but an explicitcontinue construct is rarely used:
#langracket;; Idiomatic way(for([i(in-range111)])(if(=(remainderi5)0)(printf"~a~n"i)(printf"~a, "i)));; Forces a skip, but not idiomatic because;; the logic is less obvious(for([i(in-range111)]#:unless(and(=(remainderi5)0)(printf"~a~n"i)))(printf"~a, "i))
(formerly Perl 6)
for1 ..10 { .print;if$_ %%5 {print"\n";next; }print', ';}
or without using a loop:
$_.join(", ").say for [1..5], [6..10];REBOL [Title: "Loop/Continue"URL: http://rosettacode.org/wiki/Loop/Continue]; REBOL2 does not provide a 'continue' word for loop constructs,; however, you may not even miss it:print "One liner (compare to ALGOL 68 solution):"repeat i 10 [prin rejoin [i either 0 = mod i 5 [crlf][", "]]]print [crlf "Port of ADA solution:"]for i 1 10 1 [prin ieither 0 = mod i 5 [prin newline][prin ", "]]
One liner (compare to ALGOL 68 solution):1, 2, 3, 4, 56, 7, 8, 9, 10Port of ADA solution:1, 2, 3, 4, 56, 7, 8, 9, 10
repeat i 10 [ prin i if zero? i % 5 [ prin newline continue ] prin ", "]
repeat i 10 [ prin i if i = 10 [break] either i = 5 [print ""][prin ","]]1,2,3,4,56,7,8,9,10
(This program could be simpler by using a then/else construct, but an iterate was used to conform to the task.)
/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */ do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */ call charout , j /*write the integer to the terminal. */ if j//5\==0 then do /*Not a multiple of five? Then ··· */ call charout , ", " /* write a comma to the terminal, ··· */ iterate /* ··· & then go back for next integer.*/ end say /*force REXX to display on next line. */ end /*j*/ /*stick a fork in it, we're all done. */
Program note: the comma (,) immediately after the charout BIF indicates to use the terminal output stream.
output
1, 2, 3, 4, 56, 7, 8, 9, 10
/*REXX program illustrates an example of a DO loop with an ITERATE (continue). */$= /*nullify the variable used for display*/ do j=1 for 10 /*this is equivalent to: DO J=1 TO 10 */ $=$ || j', ' /*append the integer to a placeholder. */ if j//5==0 then say left($, length($) - 2) /*Is J a multiple of five? Then SAY.*/ if j==5 then $= /*start the display line over again. */ end /*j*/ /*stick a fork in it, we're all done. */
output is the same as the 1st REXX version.
for i = 1 TO 10 see i if i % 5 = 0 see nl loop ok see ", "next
You need anIF..THEN..ELSE structure to do that in RPL.
« "" 1 10FOR j j +IF j 5 MODTHEN ", " +ELSE ""ENDNEXT DROP» 'TASK' STOfor i in 1..10 do print i if i % 5 == 0 then puts next end print ', 'end
The "for" look could be written like this:
(1..10).each do |i| ...1.upto(10) do |i| ...10.times do |n| i=n+1; ...
Without meeting the criteria (showing loop continuation), this task could be written as:
(1..10).each_slice(5){|ar| puts ar.join(", ")}fn main() { for i in 1..=10 { print!("{}", i); if i % 5 == 0 { println!(); continue; } print!(", "); }}iterate (x; [1...10]) { print(x); if (x % 5 == 0) { print("\n"); continue; }; print(", "); };There's nocontinue! in Sather. The code solve the task without forcing a new iteration.
class MAIN is main is i:INT; loop i := 1.upto!(10); #OUT + i; if i%5 = 0 then #OUT + "\n"; else #OUT + ", "; end; end; end;end;
Scala doesn't have acontinue keyword. However, you may not even miss it,if could be used here.
for (i <- 1 to 10) { print(i) if (i % 5 == 0) println() else print(", ") }Thinking In Scala© says: we avoid for loops and handle it theFunctional way:
val a = (1 to 10 /*1.*/ ).toList.splitAt(5) //2. println(List(a._1, a._2) /*3.*/ .map(_.mkString(", ") /*4.*/ ).mkString("\n") /*5.*/ )For R7RS Scheme. In this functional solution, there is no "continue". Instead, the "loop" function is directly called in the tail end (this isTail Recursion).
(import (scheme base) (scheme write))(define (loop-fn start end) (define (loop i) (if (> i end) #f (begin (display i) (cond ((zero? (modulo i 5)) (newline) (loop (+ 1 i))) (else (display ", ") (loop (+ 1 i))))))) (loop start))(loop-fn 1 10)
for i=1:10 printf("%2d ",i) if modulo(i,5)~=0 then printf(", ") continue end printf("\n")end1 , 2 , 3 , 4 , 5 6 , 7 , 8 , 9 , 10
for i in (1..10) { print i if (i %% 5) { print "\n" next } print ', '}! Loops/Continue - simula67 - 07/03/2017;begin integer i; for i:=1 step 1 until 10 do begin outint(i,5); if mod(i,5)=0 then begin outimage; goto loop end; outtext(", "); loop: end end1, 2, 3, 4, 5 6, 7, 8, 9, 10
actually works with all dialects ¹
1 to: 10 do: [ :i | [ :continue | i % 5 = 0 ifTrue: [ Transcript show: i; cr. continue value ]. Transcript show: i; show: ', '. ] valueWithExit.]
¹ if valueWithExit is not present in the Block class, it can be added as:
valueWithExit ^ self value:[^ nil]
SNOBOL4 has no looping statements or conditional statements. Indeed the only branching facilities it has are:
:(LABEL):S(LABEL):F(LABEL)(The success/failure labels can both be in the branching clause.)
Despite this, any looping structure can be performed by careful use of these.
line = i = 1LOOP le(i, 10) :F(LOOP.END) line = line i eq(remdr(i, 5), 0) :S(LOOP.OUT) line = line ', ' :(LOOP.INC)LOOP.OUT OUTPUT = line line =LOOP.INC i = i + 1 :(LOOP)LOOP.END OUTPUT = lineEND
$ snobol4 junk.sno1, 2, 3, 4, 56, 7, 8, 9, 10
con _clkmode = xtal1 + pll16x _clkfreq = 80_000_000obj ser : "FullDuplexSerial.spin"pub main | i ser.start(31, 30, 0, 115200) repeat i from 1 to 10 ser.dec(i) if i // 5 ser.str(string(", ")) next ser.str(string(13,10)) waitcnt(_clkfreq + cnt) ser.stop cogstop(0)1, 2, 3, 4, 56, 7, 8, 9, 10
> n, 1..10 s += n ? n%5, s += ", " >> n%5 #.output(s) s = ""<
1, 2, 3, 4, 56, 7, 8, 9, 10
version 9.7 or higher.
With SQL PL:
--#SET TERMINATOR @SET SERVEROUTPUT ON @BEGIN DECLARE I SMALLINT DEFAULT 1; Loop: WHILE (I <= 10) DO CALL DBMS_OUTPUT.PUT(I); SET I = I + 1; IF (MOD(I - 1, 5) = 0) THEN CALL DBMS_OUTPUT.PUT_LINE(' '); ITERATE Loop; END IF; CALL DBMS_OUTPUT.PUT(', '); END WHILE Loop;END @Output:
db2 => BEGIN...db2 (cont.) => END @DB20000I The SQL command completed successfully.1, 2, 3, 4, 56, 7, 8, 9, 10
Seecontinue in Stata help. Notice that the _continue option ofdisplay has another purpose: it suppresses the automatic newline at the end of the display command.
forvalues n=1/10 {display `n' _continueif mod(`n',5)==0 {displaycontinue}display ", " _continue}ob = Object()for (i = 1; i <= 10; ++i) { ob.Add(i) if i is 5 { Print(ob.Join(',')) ob = Object() } }Print(ob.Join(','))1,2,3,4,56,7,8,9,10ok
for i in 1...10 { print(i, terminator: "") if i % 5 == 0 { print() continue } print(", ", terminator: "")}1, 2, 3, 4, 56, 7, 8, 9, 10
for {set i 1} {$i <= 10} {incr i} { puts -nonewline $i if {$i % 5 == 0} { puts "" continue } puts -nonewline ", "}DECLARE @i INT = 0;DECLARE @str VarChar(40) = '';WHILE @i<10 BEGIN SET @i = @i + 1; SET @str = @str + CONVERT(varchar(2),@i); IF @i % 5 = 0 BEGIN PRINT @str; SET @str ='' CONTINUE; END SET @str = @str +', '; END;
$$ MODE TUSCRIPTnumbers=""LOOP n=1,10numbers=APPEND (numbers,", ",n)rest=n%5IF (rest!=0) CYCLE PRINT numbers numbers=""ENDLOOP
1, 2, 3, 4, 56, 7, 8, 9, 10
+1⇡10⍚(&pf⨬(", "|"\n")=0◿5&pf.)Z=1while (( Z<=10 )); do echo -e "$Z\c" if (( Z % 5 != 0 )); then echo -e ", \c" else echo -e "" fi (( Z++ ))done
for ((i=1;i<=10;i++)); do echo -n $i if [ $((i%5)) -eq 0 ]; then echo continue fi echo -n ", "done
yes \ | cat -n | head -n 10 | xargs -n 5 echo | tr ' ' ,
decl int ifor (set i 1) (< i 11) (inc i) if (= (mod i 5) 0) out i endl console continue end if out i ", " consoleend for
let write = process.stdout.writefor i in range(10) { let n = i + 1 write(n.toString()) if (n == 5) { write("\n") continue } if (n < 10) {write(", ")}}%newline { [ LIT2 0a -Console/write ] DEO }%comma { [ LIT2 ", -Console/write ] DEO }%space { [ LIT2 20 -Console/write ] DEO }%MOD ( a b -- a%b ) { DIVk MUL SUB }|18 @Console/write|100 #0b01&loopDUP print-dec DUP #05 MOD ?{ newline !&continue }comma space &continue INC GTHk ?&loopPOP2BRK@print-dec ( dec -- )DUP #64 DIV print-num/tryDUP #0a DIV print-num/try( >> )@print-num ( num -- )#0a DIVk MUL SUB [ LIT "0 ] ADD .Console/write DEOJMP2r&try ( num -- )DUP ?print-numPOP JMP2r1, 2, 3, 4, 56, 7, 8, 9, 10
for (int i = 1; i <= 10; i++) { stdout.printf("%d", i); if (i % 5 == 0) { stdout.printf("\n"); continue; } stdout.printf(", ");}Public Sub LoopContinue() Dim value As Integer For value = 1 To 10 Debug.Print value; If value Mod 5 = 0 Then 'VBA does not have a continue statement Debug.Print Else Debug.Print ","; End If Next valueEnd Sub
for (#1 = 1; #1 <= 10; #1++) { Num_Type(#1, LEFT+NOCR) if (#1 % 5 == 0) { Type_Newline Continue } Message(", ")}fn main() { for i in 1..11 { print(i) if i%5==0{ println('') continue } print(', ') }}1, 2, 3, 4, 56, 7, 8, 9, 10
From v0.4.0 Wren has acontinue keyword which works in the expected fashion.
for (i in 1..10) { System.write(i) if (i%5 == 0) { System.print() continue } System.write(", ")}System.print()1, 2, 3, 4, 56, 7, 8, 9, 10
The code got really long, because i manually convert the numbers to ASCII,which gets harder with multiple digits(the number 10).The way you implement continue in X86 Assembly is the same way as how you would create a loop:you just implement a (conditional) jump to another line of code.
extern _printfsection .data output db 0,0,0,0 reversedOutput db 0,0 section .textglobal _main_main: mov ecx, 0 looping: inc ecx mov eax, ecx push ecx cmp ecx, 5 je do5 cmp ecx, 10 je do10 don: call createOutput mov [eax+1], byte 0x2c mov [eax+2], byte 0x20 push eax call _printf add esp, 4 pop ecx jmp looping do5: call createOutput mov [eax+1], byte 0x0a push eax call _printf add esp, 4 pop ecx jmp looping do10: call createOutput mov [eax+2], byte 0x0a push eax call _printf add esp, 4 pop ecx xor eax, eax ret createOutput: ;parameter in eax ;eax between 1 and 99 push ebx mov ecx, 0 clearOutput: mov [output+ecx], byte 0 cmp ecx, 3 je next inc ecx jmp clearOutput next: mov ecx, 0 mov ebx, 10 cOlooping: xor edx, edx div ebx mov [reversedOutput+ecx], dl add [reversedOutput+ecx], byte 0x30 cmp eax, 0 je reverse cmp ecx, 1 je reverse inc ecx jmp cOlooping reverse: mov ecx, -1 mov ebx, 0 name: inc ecx neg ecx mov dl, [reversedOutput+ecx+1] neg ecx cmp dl, 0 je name mov [output + ebx], dl inc ebx cmp ecx, 1 jl name mov eax, output pop ebx ret
1, 2, 3, 4, 56, 7, 8, 9, 10
PROGRAM "loopcontinue"DECLARE FUNCTION Entry()FUNCTION Entry() FOR i% = 1 TO 10 PRINT i%; IF i% MOD 5 = 0 THEN PRINT DO NEXT ' It looks like DO FOR backs to the FOR with the current value of i% END IF PRINT ", "; NEXT i%END FUNCTIONEND PROGRAM
1, 2, 3, 4, 56, 7, 8, 9, 10
Like Ada and ALGOL there's no 'continue' command. The task is solved verysimply anyway. The commands 'int' and 'rem' are shown spelled out here.Only the first three characters of a command are required.
code CrLf=9, IntOut=11, Text=12;integer N;for N:= 1 to 10 do [IntOut(0, N); if remainder(N/5) \#0\ then Text(0, ", ") else CrLf(0)]
1, 2, 3, 4, 56, 7, 8, 9, 10
for i = 1 to 10 print str$(i); if mod(i, 5) = 0 then print continue end if print ", ";nextprintend
foreach n in ([1..10]){print(n); if(n%5==0){println(); continue;} print(", ")}// or foreach n in ([1..10]){print(n,(n%5) and ", " or "\n")}const std = @import("std");pub fn main() !void { const stdout_wr = std.io.getStdOut().writer(); var i: i8 = 1; while (i <= 10) : (i += 1) { try stdout_wr.print("{d}", .{i}); if (i == 5) { try stdout_wr.writeAll("\n"); continue; } try stdout_wr.writeAll(", "); }}