Loops/Infinite: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Joy}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 25:
=={{header|11l}}==
<
print(‘SPAM’)</
=={{header|360 Assembly}}==
This for sure will result in a severe WTO buffer shortage.
<syntaxhighlight lang="360 assembly">
INFINITE CSECT , this PGM control section
INFINITE AMODE 31 addressing mode 31 bit
Line 47:
RETURN PR , return to caller
END INFINITE
</syntaxhighlight>
=={{header|4DOS Batch}}==
<
do forever
echo SPAM
enddo</
=={{header|6502 Assembly}}==
Specific OS/hardware routines for printing are left unimplemented.
<
PrintLoop: LDA MSG,x
JSR PrintAccumulator ;routine not implemented
Line 66:
BEQ InfiniteLoop
MSG .byte "SPAM", $0A</
=={{header|6800 Assembly}}==
<syntaxhighlight lang="text"> .cr 6800
.tf spam6800.obj,AP1
.lf spam6800
Line 99:
;=====================================================;
string .as "SPAM",#13,#10,#0
.en</
=={{header|68000 Assembly}}==
Hardware-specific routines for I/O are left unimplemented and just displayed as a subroutine, as this is not the focus of the task.
<
LEA Message,A0
JSR PrintString
Line 110:
Message:
DC.B "SPAM",13,10,0
EVEN</
=={{header|8086 Assembly}}==
{{works with|https://www.dosbox.com DOSBox}}
===Loading Immediates===
<
mov ah,02h
mov dl,'S' ;VASM replaces a character in single quotes with its ascii equivalent
Line 135:
int 21h
jmp Spam</
===Loading From A Data Source===
<
mov ax, seg SpamMessage ;load into ax whatever segment the address of our message is in.
mov ds, ax ;segment registers on the original 8086 must be loaded from a register
Line 154:
jmp SpamInner
SpamMessage db "SPAM",13,10,0</
=={{header|8th}}==
One way:
<
: inf "SPAM\n" . recurse ;
</syntaxhighlight>
Another way:
<
: inf repeat "SPAM\n" . again ;
</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program infinite64.s */
Line 201:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|ACL2}}==
<
(declare (xargs :mode :program))
(if nil
nil
(prog2$ (cw "SPAM~%")
(spam))))</
=={{header|Action!}}==
<
DO
PrintE("SPAM")
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Infinite.png Screenshot from Atari 8-bit computer]
Line 235:
=={{header|ActionScript}}==
<
trace("SPAM");
}</
=={{header|Ada}}==
<
Put_Line("SPAM");
end loop;</
=={{header|Agena}}==
Tested with Agena 2.9.5 Win32
<
print( "SPAM" )
od</
=={{header|Aime}}==
<
o_text("SPAM\n");
}</
=={{header|ALGOL 60}}==
Line 265:
'''end'''
{{works with|ALGOL 60|OS/360}}
<
'INTEGER' I;
'FOR' I := 1 'STEP' 0 'UNTIL' 2 'DO'
OUTSTRING(1,'('SPAM')')
'END'</
=={{header|ALGOL 68}}==
<
printf($"SPAM"l$)
OD</
Or the classic "dynamic halt":
<
printf($"SPAM"l$);
loop x</
=={{header|ALGOL W}}==
<
for i := 1 step 0 until 2 do write( "SPAM" )
end.</
=={{header|AmigaE}}==
<
LOOP
WriteF('SPAM')
ENDLOOP
ENDPROC</
=={{header|AppleScript}}==
<
log "SPAM"
end repeat</
=={{header|ARM Assembly}}==
<syntaxhighlight lang="arm_assembly">
.global main
Line 310:
message:
.asciz "SPAM\n"
</syntaxhighlight>
=={{header|ArnoldC}}==
<
STICK AROUND @NO PROBLEMO
TALK TO THE HAND "SPAM"
CHILL
YOU HAVE BEEN TERMINATED</
=={{header|Arturo}}==
<
print "SPAM"
]</
=={{header|AutoHotkey}}==
<
MsgBox SPAM `n</
=={{header|AWK}}==
<
while(1) {
print "SPAM"
}
}</
=={{header|Axe}}==
Warning: running this program will cause you to need to reset your calculator, thereby losing any user data stored in RAM.
<
Disp "SPAM",i
End</
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
Old-fashioned syntax:
<
print "SPAM"
wend</
Standard BASIC:
<
print "SPAM"
loop</
Also
<
print "SPAM"
next i</
{{works with|Applesoft BASIC}}
Line 365:
The most intuitive method is to use the <code>GOTO</code> statement.
<
20 goto 10</
Generally, using <code>GOSUB</code> in place of <code>GOTO</code> is incorrect. Some programming bugs come about when a <code>GOSUB</code> causes a potentially infinite loop, however, eventually stack memory will fill up and cause a terminating error as shown in this Commodore BASIC example:
Line 386:
The solution is to keep the stack empty, however, this will also clear all variables used and prevent the use of <code>RETURN</code>ing from the "subroutine". This is accomplished with the <code>CLEAR</code> (or <code>CLR</code> in Commodore BASIC) placed at the start of the loop.
<
<
Rather than a <code>GOTO</code>, instead we can use a <code>FOR... NEXT</code> statement:
<
20 print "SPAM";
30 next i</
In most cases, we can also call the <code>RUN</code> command from within the program.
<
20 run</
<code>IF... THEN</code> has an implied <code>GOTO</code> on some BASICs...
<
==={{header|Applesoft BASIC}}===
<
==={{header|BASIC256}}===
<
print "SPAM"
end while</
==={{header|Commodore BASIC}}===
Line 448:
==={{header|IS-BASIC}}===
<
110 PRINT "SPAM"
120 LOOP</
==={{header|QB64}}===
<
Do 'Alternatively this could have a conditional, "Do While 1"
Print "SPAM"
Line 461:
While 1
Print "SPAM"
Wend</
==={{header|True BASIC}}===
<
PRINT "SPAM"
LOOP
END</
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">do
print "SPAM"
loop</
O también
<
print "SPAM"
wend</
=={{header|Batch File}}==
Using <code>goto</code>:
<
:loop
echo SPAM
goto loop</
Another variant which uses Windows NT's <code>for</code> statement:
{{works with|Windows NT|4 or later}}
<
This essentially is a counted loop which starts at <code>1</code>, increments by <code>0</code> and stops when the counter reaches <code>2</code>.
=={{header|BBC BASIC}}==
<
PRINT "SPAM"
UNTIL FALSE</
=={{header|bc}}==
<
"</
=={{header|BCPL}}==
<
let start() be writes("SPAM*N") repeat</
=={{header|beeswax}}==
<
bN`M`<</
=={{header|Befunge}}==
Because the 2-D code space is toroidal, all loops are infinite
unless explicitly stopped with '''@'''.
<
=={{header|blz}}==
<
print("SPAM")
end</
=={{header|bootBASIC}}==
Using <code>goto</code>:
<
20 goto 10</
Using <code>run</code>:
<
20 run</
=={{header|BQN}}==
Line 533:
The main way of performing an infinite loop in BQN is using recursion.
<
will likely end in a stack overflow.
=={{header|Bracmat}}==
<syntaxhighlight lang
=={{header|Brainf***}}==
Optimized for code size:
<
[+++.---.<.>---.+++>.<]</
Optimized for execution speed:
<
[-> 8++++++++ > 8++++++++ > 6++++++ > 8++++++++ > 1+ <<<<<]>
83+++ > 80 > 65+++++ > 77--- <<<
[.>.>.>.>.<<<<]</
=={{header|Brat}}==
<
=={{header|C}}==
<
or
<
or
<
or
<
or
<syntaxhighlight lang="c">
spam: puts("SPAM");
goto spam;
</syntaxhighlight>
=={{header|C sharp|C#}}==
<
{
Console.WriteLine("SPAM");
}</
=={{header|C++}}==
{{trans|C}}
<
std::cout << "SPAM\n";</
or
<
std::cout << "SPAM\n";</
or
<
std::cout << "SPAM\n";
while (true);</
=={{header|Chapel}}==
<
=={{header|ChucK}}==
<syntaxhighlight lang="text">
while(true) <<<"SPAM">>>;
</syntaxhighlight>
=={{header|Clojure}}==
<
=={{header|COBOL}}==
<
PROGRAM-ID. Spam.
Line 608:
GOBACK
.</
[[OpenCOBOL]] supports a <code>FOREVER</code> clause for <code>PERFORM</code> which will have the same effect.
=={{header|CoffeeScript}}==
<
console.log 'SPAM'
</syntaxhighlight>
=={{header|ColdFusion}}==
Line 620:
With tags:
<
SPAM
</cfloop></
With script:
<
while( true != false )
{
writeOutput( "SPAM" );
}
</cfscript></
=={{header|Comal}}==
<
PRINT "SPAM"
ENDLOOP</
=={{header|Common Lisp}}==
<
=== Using DO ===
<
(do () ; Not initialization
(nil) ; Not break condition
(print "SPAM")) ; On every loop as requested
</syntaxhighlight>
{{out}}
Line 653:
=={{header|Corescript}}==
<syntaxhighlight lang="corescript">
:top
print Spam!
goto top
</syntaxhighlight>
=={{header|Cowgol}}==
<
loop
print("Spam\n");
end loop;</
=={{header|Crystal}}==
<
puts "SPAM"
end</
Using <code>while</code>/<code>until</code>:
<
puts "SPAM"
end</
<
puts "SPAM"
end</
Using an infinite range:
<
puts "SPAM"
end</
=={{header|D}}==
Some common ways to create an infinite printing loop:
<
void main() {
while (true)
writeln("SPAM");
}</
<
void main() {
Line 699:
writeln("SPAM");
while (true);
}</
<
void main() {
for ( ; ; )
writeln("SPAM");
}</
<
void main() {
Line 714:
writeln("SPAM");
goto LOOP;
}</
=={{header|Dart}}==
<syntaxhighlight lang="text">
main() {
while(true) {
Line 723:
}
}
</syntaxhighlight>
=={{header|dc}}==
<
]P dx]dx</
This loop is a tail-recursive function.
Line 735:
=={{header|DCL}}==
<
$ write sys$output "SPAM"
$ goto loop</
=={{header|Delphi}}==
Line 743:
=={{header|Draco}}==
<
while true do
writeln("SPAM")
od
corp</
=={{header|DWScript}}==
<
PrintLn('SPAM');</
=={{header|Dyalect}}==
<
print("SPAM")
}</
=={{header|Déjà Vu}}==
<
!print "SPAM"</
Infinite recursion thanks to tail calls:
<
!print "SPAM"
recurse
call</
=={{header|E}}==
<
println("SPAM")
}</
<
println("SPAM")
f <- ()
}
f <- ()</
The difference between these is that in the second,
Line 787:
=={{header|EDSAC order code}}==
The EDSAC instruction set does not include an unconditional jump: it is necessary to synthesize it by using either an <code>E</code> "branch on accumulator sign bit clear" or <code>F</code> "branch on accumulator sign bit set" order, in circumstances where the condition is guaranteed to be met. For this specific task, guaranteeing it is trivial: printing characters does not change the contents of the accumulator at all. The solution presented here, however, is more general. We use a <code>T</code> "transfer and clear" order to store the accumulator's contents in storage address <i>θ</i>+17, then jump back to the beginning of the loop and reload the accumulator with an <code>A</code> "add" order. Note that the storage address used as a temporary variable should be set to zero on entry to the loop.
<
=============
Line 819:
[ 17 ] PF
EZPF</
=={{header|Ela}}==
Line 825:
===Direct Approach===
<
loop () = do
Line 831:
loop ()
loop () ::: IO</
===Non-strict version===
<
xs = "SPAM"::xs
Line 844:
takeit (num - 1) xs
_ = takeit 10 xs ::: IO</
=={{header|Elena}}==
ELENA 4.x:
<
{
while (true)
Line 854:
console.writeLine:"spam"
}
}</
=={{header|Elixir}}==
<
def infinite do
IO.puts "SPAM"
Line 864:
end
Loops.infinite</
or
<
=={{header|Emacs Lisp}}==
<
(message "SPAM"))</
=={{header|Erlang}}==
<
-module (main).
-export ([main/0]).
Line 881:
io:fwrite( "SPAM~n" ),
main().
</syntaxhighlight>
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
LOOP
PRINT("SPAM")
END LOOP
</syntaxhighlight>
You can use also WHILE TRUE..END WHILE or REPEAT...UNTIL FALSE loops.
=={{header|Euphoria}}==
<syntaxhighlight lang="euphoria">
while 1 do
puts(1, "SPAM\n")
end while
</syntaxhighlight>
=={{header|F Sharp|F#}}==
<
// Imperative Solution
while true do
Line 908:
printfn "SPAM"
forever ()
</syntaxhighlight>
=={{header|Factor}}==
Tail recursion:
<
Looping combinators:
<
<
[ "SPAM" print ] forever</
=={{header|FALSE}}==
<
"]#</
=={{header|Fantom}}==
<
class Main
{
Line 935:
}
}
</syntaxhighlight>
=={{header|Fermat}}==
<
=={{header|Fish}}==
<
=={{header|Forth}}==
<
=={{header|Fortran}}==
FORTRAN 77
<
10 WRITE(*,*) 'SPAM'
GO TO 10
END
</syntaxhighlight>
Fortran 90
<
program spam
implicit none
Line 962:
end do
end program spam
</syntaxhighlight>
=={{header|Fortress}}==
<
component loops_infinite
export Executable
Line 972:
end
end
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
Do
Print "SPAM"
Loop</
=={{header|Frink}}==
<
while true
println["SPAM"]
</syntaxhighlight>
=={{header|FutureBasic}}==
Loop de loop -- whose great idea was this?
<
dispatchglobal
Line 997:
dispatchend
HandleEvents</
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=e63dcdc939f8a7dcfd3194d884f8d4a5 Click this link to run this code]'''
<
Do
Line 1,007:
Loop
End</
=={{header|GAP}}==
<
Print("SPAM\n");
od;</
=={{header|GB BASIC}}==
<
20 goto10</
=={{header|GlovePIE}}==
GlovePIE does not natively support multiple lines of output. As such, this code continuously changes the single line of output to SPAM. The below code does this without specifying an infinite loop because all GlovePIE scripts loop indefinitely until the program is stopped.
<
=={{header|GML}}==
<
show_message("SPAM")</
=={{header|Go}}==
<
import "fmt"
Line 1,035:
fmt.Printf("SPAM\n")
}
}</
=={{header|Groovy}}==
<
println 'SPAM'
}</
=={{header|Halon}}==
<
echo "SPAM";
}</
or (due to optimizations, these are equally fast)
<
echo "SPAM";
}</
=={{header|Hare}}==
<
export fn main() void = {
Line 1,058:
fmt::println("SPAM")!;
};
};</
=={{header|Haskell}}==
<
or
<
fix (putStrLn "SPAM" >>) </
=={{header|Haxe}}==
<
Sys.println("SPAM");</
=={{header|hexiscript}}==
<
=={{header|HicEst}}==
<
WRITE() "SPAM"
ENDDO</
=={{header|HolyC}}==
<
=={{header|Icon}} and {{header|Unicon}}==
There are several ways to write infinite loops in Icon. The most straightforward would be with repeat.
<
repeat write("SPAM")
end</
Alternately one could use one of these:
<
...
while write("SPAM") # always succeeds, needs failure to break
Line 1,096:
while write(|"SPAM") # this is a common mistake that results in an endless loop
...
while write(1 to 5) # a clearer version of the same mistake that generates endless 1's</
=={{header|IDL}}==
<syntaxhighlight lang
=={{header|Intercal}}==
Assuming Turing Text I/O with 8-bit ASCII-compatible character set, using COME FROM:
<
PLEASE ,1 <- #5
DO ,1 SUB #1 <- #54
Line 1,114:
DO READ OUT ,1
(2) DO ,1 SUB #1 <- #134
(1) PLEASE ABSTAIN FROM (2)</
=={{header|Io}}==
<
=={{header|J}}==
<
Alternatively,
<
This second implementation relies on numeric inaccuracies in IEEE floating point notation.
Line 1,132:
=={{header|Java}}==
<
System.out.println("SPAM");
}</
<
System.out.println("SPAM");
}</
=={{header|JavaScript}}==
<
<
=={{header|Joy}}==
<syntaxhighlight lang=
["SPAM\n" putchars] loop.</syntaxhighlight>
=={{header|jq}}==
<
{{Out}}
"SPAM"
Line 1,158:
=={{header|Jsish}}==
<
=={{header|Julia}}==
<syntaxhighlight lang="julia">
while true
println("SPAM")
end
</syntaxhighlight>
{{out}}
<pre>
Line 1,179:
=={{header|K}}==
<
=={{header|Kotlin}}==
<
fun main(args: Array<String>) {
while (true) println("SPAM")
}</
=={{header|LabVIEW}}==
Line 1,192:
=={{header|Lambdatalk}}==
<
{def loops_infinite
{lambda {}
Line 1,200:
{loops_infinite}
-> SPAM forever...
</syntaxhighlight>
=={{header|Lang5}}==
<
=={{header|Lasso}}==
<
while(1 > 0) => {^
'SPAM\r'
^}</
=={{header|Liberty BASIC}}==
<CTRL><Break> is used to terminate such loops.
<syntaxhighlight lang="lb">
while 1
print "SPAM"
wend
end
</syntaxhighlight>
=={{header|Lily}}==
<
while 1: print("SPAM")
</syntaxhighlight>
=={{header|Lingo}}==
<
put "SPAM"
end repeat</
=={{header|Lisaac}}==
Line 1,236:
=={{header|LiveCode}}==
<
put "SPAM" & return
end repeat</
=={{header|Logo}}==
<
=={{header|LOLCODE}}==
<
CAN HAS STDIO?
IM IN YR LOOP
VISIBLE "SPAM"
IM OUTTA YR LOOP
KTHXBYE</
=={{header|Lua}}==
<
while true do
print("SPAM")
Line 1,261:
print("SPAM")
until false
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
Line 1,267:
If Esc works then Ctrl + Y (and other letters except C, A, Z, X, N, M. F, L), open Control form, which we can do: Next Step, Slow Flow, Stop, and we can show code,current stack, variables, or execute immediate statements. This works only in console, not in M2000 forms.
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Print "SPAM"
Line 1,273:
}
Checkit
</syntaxhighlight>
Using a Repeat (or Do) - Always block
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Repeat {
Line 1,282:
}
Checkit
</syntaxhighlight>
Printing text rendering using Report.
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
\\ stop in every 2/3 of cosole lines
Line 1,296:
Report {SPAM
}
</syntaxhighlight>
=={{header|M4}}==
<
spam')
spam</
=={{header|Make}}==
<
@echo SPAM
$(MAKE)</
=={{header|Malbolge}}==
<
bP&A@?>=<;:9876543210/.-,+*)('&%$T"!~}|;]yxwvutslUSRQ.yx+i)J9edFb4`_^]\yxwRQ)(TSRQ]m!G0KJIyxFvDa%_@?"=<5:98765.-2+*/.-,+*)('&%$#"!~}|utyrqvutsrqjonmPkjihgfedc\DDYAA\>>Y;;V886L5322G//D,,G))>&&A##!7~5:{y7xvuu,10/.-,+*)('&%$#"yb}|{zyxwvutmVqSohmOOjihafeHcEa`YAA\[ZYRW:U7SLKP3NMLK-I,GFED&%%@?>=6;|9y70/4u210/o-n+k)"!gg$#"!x}`{zyxZvYtsrqSoRmlkjLhKfedcEaD_^]\>Z=XWVU7S6QPON0LKDI,GFEDCBA#?"=};438y6543s1r/o-&%*k('&%e#d!~}|^z]xwvuWsVqponPlOjihgIeHcba`B^A\[ZY;W:UTSR4PI2MLKJ,,AFE(&B;:?"~<}{zz165v3s+*/pn,mk)jh&ge#db~a_{^\xwvoXsrqpRnmfkjMKg`_GG\aDB^A?[><X;9U86R53ONM0KJC,+FEDC&A@?!!6||3876w4-tr*/.-&+*)('&%$e"!~}|utyxwvutWlkponmlOjchg`edGba`_XW\?ZYRQVOT7RQPINML/JIHAFEDC&A@?>!<;{98yw5.-ss*/pn,+lj(!~ff{"ca}`^z][wZXtWUqTRnQOkNLhgfIdcFaZ_^A\[Z<XW:U8SRQPOHML/JIHG*ED=%%:?>=~;:{876w43210/(-,+*)('h%$d"ca}|_z\rqYYnsVTpoRPledLLafIGcbE`BXW??TY<:V97S64P31M0.J-+G*(DCB%@?"=<;|98765.3210p.-n+$)i'h%${"!~}|{zyxwvuXVlkpSQmlOjLbafIGcbE`BXW??TY<:V97S64P31M0.J-+G*(D'%A@?"=<}:98y6543,1r/.o,+*)j'&%eez!~a|^tsx[YutWUqjinQOkjMhJ`_dGEaDB^A?[><X;9U86R53O20LKJ-HG*ED'BA@?>7~;:{y7x5.3210q.-n+*)jh&%$#"c~}`{z]rwvutWrkpohmPkjihafI^cba`_^A\[>YXW:UTS5QP3NM0KJ-HGF?D'BA:?>=~;:z8765v32s0/.-nl$#(ig%fd"ca}|_]yrqvYWsVTpSQmPNjMKgJHdGEa`_B]\?ZY<WVUTMR5PO20LK.IHA))>CB%#?87}}49zx6wu3tr0qo-nl*ki'hf$ec!~}`{^yxwvotsrUponQlkMihKIe^]EEZ_B@\?=Y<:V97S64P31M0.J-+GFE(C&A@?8=<;:{876w43s10qo-&%kk"'hf$ec!b`|_]y\ZvYWsVTpSQmlkNiLgf_dcba`C^]\?ZY;WV97SLK33HM0.J-+G*(D'%A$">!};|z8yw543t1r/(-,+*)(i&%fd"!~}|_t]xwvutslqTonmPkjLhKIeHFbEC_^A?[TSX;9UT7R4JIN1/K.,H+)E(&B%#?"~<}{987x/4ussr).o,+l)(h&ge#db~a_{^\x[YutWrTjinQOkNLhgJeG]\aDB^]@[=SRW:877LQP3N0FEJ-+**?DC&A#98=~|:98yx/4u21rp(',mk)(ig%|{"ca}`^z][wZXtWUqTRnQOkNLhKIedcFE`YB@@?ZYRW:UTS6QPO11F..CHGF)(CB;@#>!~;XzV7gwu-QrrqMoJIkZF'WC$#AbQ`_{^L9wI64"VDConzl+j);JJ%qGFEZ~}]{ygwRuc8aSq44"H1Y.iV,e*RQ
</syntaxhighlight>
=={{header|Maple}}==
<syntaxhighlight lang="maple">
> do print(SPAM) end;
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
Print@"SPAM";
]</
=={{header|MATLAB}} / {{header|Octave}}==
<
fprintf('SPAM\n')
end</
=={{header|Maxima}}==
<
=={{header|MAXScript}}==
<
=={{header|MelonBasic}}==
Using <code>Goto:1</code>:
<
Goto:1</
Using <code>Goto:start</code>:
<
Goto:start</
=={{header|Metafont}}==
<
=={{header|Microsoft Small Basic}}==
With <code>While</code>.
<
While "True"
TextWindow.WriteLine("SPAM")
EndWhile
</syntaxhighlight>
With <code>Goto</code>.
<
loopStart:
TextWindow.WriteLine("SPAM")
Goto loopStart
</syntaxhighlight>
=={{header|min}}==
{{works with|min|0.19.3}}
<
=={{header|MIPS Assembly}}==
Thanks to [https://www.chibialiens.com/mips/ Chibialiens.com] for the header/footer, bitmap font, and print routines.
<
.include "\SrcAll\BasicMacros.asm"
.include "\SrcPSX\MemoryMap.asm"
Line 1,400:
.include "..\\SrcAll\monitor.asm"
.include "\SrcN64\Footer.asm"</
{{out}}
[https://ibb.co/rpH9bVR Screenshot of Nintendo 64 emulator]
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 2 3 4 С/П БП 00</
''Note'': because this device has no text output instead of "SPAM" was used the number (1234).
=={{header|Modula-2}}==
<
InOut.WriteString ("SPAM");
InOut.WriteLn
END;</
=={{header|Modula-3}}==
<
IO.Put("SPAM\n");
END;</
=={{header|Monte}}==
<syntaxhighlight lang="monte">
while (true):
traceln("SPAM")
</syntaxhighlight>
=={{header|MontiLang}}==
<
|SPAM| PRINT .
ENDWHILE</
Note that <code>TRUE</code> is simply a variable equal to 1. <code>WHILE 1</code>, any number larger than 0 or any string with a length more than 0 would also work
=={{header|MOO}}==
<
player:tell("SPAM");
endwhile</
=={{header|MUMPS}}==
<syntaxhighlight lang="mumps">
FOR WRITE "SPAM",!
</syntaxhighlight>
=={{header|Nanoquery}}==
<
println "SPAM"
end</
=={{header|Nemerle}}==
<
Or, using recursion:
<
{
WriteLine("SPAM");
loop();
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols nobinary
Line 1,467:
say 'SPAM'
end spam
</syntaxhighlight>
=={{header|NewLISP}}==
<
=={{header|Nim}}==
<
echo "SPAM"</
=={{header|NS-HUBASIC}}==
Using <code>FOR</code>:
<
20 PRINT "SPAM"
30 NEXT</
Using <code>GOTO</code>:
<
20 GOTO 10</
Using <code>RUN</code>:
<
20 RUN</
=={{header|Oberon-2}}==
<
MODULE InfiniteLoop;
IMPORT
Line 1,500:
END
END InfiniteLoop.
</syntaxhighlight>
=={{header|Objeck}}==
<
while(true) {
"SPAM"->PrintLine();
};
</syntaxhighlight>
=={{header|OCaml}}==
<
print_endline "SPAM"
done</
or
<
print_endline "SPAM";
inf_loop()
in
inf_loop()</
Seen like this it looks like the "too much functional" danger when a "while" loop looks far simpler, but the functional loop may be useful to provide data to the next loop without using mutable variable.
=={{header|Occam}}==
<
PROC main (CHAN BYTE screen!)
WHILE TRUE
out.string("SPAM*c*n", 0, screen)
:</
=={{header|Octave}}==
<
disp("SPAM")
endwhile</
=={{header|Oforth}}==
<
=={{header|Ol}}==
<
(let loop ()
(display "SPAM")
(loop))
</syntaxhighlight>
=={{header|OPL}}==
<
LOCAL loop%
loop%=1
Line 1,554:
PRINT "SPAM"
ENDWH
ENDP</
=={{header|Oz}}==
<
{Show 'SPAM'}
end</
=={{header|PARI/GP}}==
<
print("SPAM")
);</
For a shorter version, note that <code>print</code> returns <code>gnil</code> which is evaluated as <code>false</code>.
A 'cheating' solution might use <code>print(SPAM)</code> on the hope that the variable SPAM is uninitialized and hence prints as the monomial in itself.
But with the <code>'</code> operator that evaluation can be forced, regardless of the current value (if any) of that variable:
<syntaxhighlight lang
=={{header|Pascal}}==
<
writeln('SPAM');</
Alternatively:
<
writeln('SPAM')
until false;</
=={{header|Perl}}==
<
print "SPAM\n";
}</
or equivalently
<
=={{header|Phix}}==
<!--<
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"SPAM\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</
=={{header|PHP}}==
<
echo "SPAM\n";</
=={{header|PicoLisp}}==
<
=={{header|Pike}}==
<
while(1)
write("SPAM\n");
</syntaxhighlight>
=={{header|PILOT}}==
<
type:SPAM
jump:*TypeSpam</
=={{header|Pixilang}}==
<
fputs("SPAM\n")
go start</
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
do forever;
put list ('SPAM'); put skip;
end;</
=={{header|Plain English}}==
When <code>Repeat.</code> appears by itself, execution proceeds from the beginning of the routine. Normally you would include a conditional statement to break or exit when a condition is met, but not in this case.
<
Start up.
Write SPAM forever.
Line 1,633:
To write SPAM forever:
Write "SPAM" to the console.
Repeat.</
=={{header|plainTeX}}==
Compile in console mode, with, e.g. "pdftex <file name>".
<
\def\spam{\message{SPAM^^J}\spam}%
\spam</
=={{header|Pop11}}==
<
printf('SPAM', '%p\n');
endwhile;</
=={{header|PostScript}}==
simple infinite loop:
<syntaxhighlight lang
A bit more complex infinite loop:
<
/spam
{ (SPAM\n) print flush }
Line 1,661:
%start spamming!
go</
=={{header|PowerShell}}==
<
"SPAM"
}</
=={{header|Prolog}}==
<
=={{header|Pure Data}}==
Line 1,675:
Screenshot: https://i.imgur.com/IrwaafZ.png
<
#X obj 17 75 print;
#X msg 17 55 SPAM;
Line 1,682:
#X connect 1 0 0 0;
#X connect 2 0 1 0;
#X connect 3 0 2 0;</
Notes: the loop is started by clicking the |1(, a [loadbang] could additionally be used. An [until] object, sent a bang, will loop forever, but will hang Pure Data, whereas a high-speed metro will function perfectly.
Line 1,688:
=={{header|PureBasic}}==
===Repeat/Forever===
<
PrintN("SPAM")
ForEver</
===Goto===
<
PrintN("SPAM")
Goto PrintIt</
=={{header|Python}}==
In Python 2:
<
print "SPAM"</
In python 3:
<
print("SPAM")</
Note: one can also use: "True" or any other non-false value.
Line 1,713:
=={{header|Quackery}}==
<
=={{header|R}}==
Line 1,719:
To see this run either run in terminal mode, right click on the GUI window and deselect "Buffered Output" prior to execution, or add a call to flush.console() in the loop.
<
=={{header|Racket}}==
<
#lang racket
Line 1,736:
(for ([i (in-naturals)])
(displayln "SPAM"))
</syntaxhighlight>
=={{header|Raku}}==
Line 1,742:
{{works with|Rakudo Star|2010.08}}
<syntaxhighlight lang="raku"
say 'SPAM';
}</
In addition, there are various ways of writing lazy, infinite lists in Raku:
<syntaxhighlight lang="raku"
print "SPAM\n", ~* ... *; # sequence operator
map {say "SPAM"}, ^Inf; # upto operator</
=={{header|Rapira}}==
<
output: "SPAM"
od</
=={{header|REBOL}}==
<
=={{header|Red}}==
<
print "SPAM"
]</
=={{header|ReScript}}==
<
Js.log("SPAM")
}</
or
<
Js.log("SPAM")
inf_loop()
}</
=={{header|Retro}}==
<
=={{header|REXX}}==
===simple===
<
do forever
Line 1,786:
end /*DO forever*/
/*control will never reach here. */
/*don't stick a fork in it. */</
===esoteric===
<
do while 1==1 /*esoteric "forever" clause. */
Line 1,795:
end /*DO while 1==1*/
/*control will never reach here. */
/*don't stick a fork in it. */</
===GO TO version===
<
tell_it: say 'SPAM'
Line 1,804:
/*control will never reach here. */
/*don't stick a fork in it. */</
===too clever by half===
<
do until 0>1 /*too-clever-by-half forever loop*/
Line 1,812:
end /*DO until 0>1*/
/*control will never reach here. */
/*don't stick a fork in it. */</
=={{header|Ring}}==
<
while true
see "Spam"
end
</syntaxhighlight>
=={{header|Robotic}}==
This will display the word '''SPAM''' at the bottom of the screen indefinitely:
<
: "infinite_loop"
* "SPAM"
goto "infinite_loop"
</syntaxhighlight>
=={{header|Ruby}}==
<
</syntaxhighlight>
=={{header|Run BASIC}}==
<
while 1
print "Spam"
wend</
=={{header|Rust}}==
<
loop {
println!("SPAM");
}
}</
=={{header|S-lang}}==
<
=={{header|Salmon}}==
<
"SPAM"!;</
=={{header|Sather}}==
<
main is
loop
Line 1,861:
end;
end;
end;</
=={{header|Scala}}==
<
println("SPAM")</
=={{header|Scheme}}==
<
(lambda (x) (display "SPAM") (newline) (x x)))
</syntaxhighlight>
or, less Schemishly but with less redundancy:
<
=={{header|Scilab}}==
{{works with|Scilab|5.5.1}}
<syntaxhighlight lang="text">while %T
printf("SPAM\n")
end</
{{out}}
<pre>SPAM
Line 1,889:
=={{header|sed}}==
<
s/.*/SPAM/
p
t loop</
Sed requires at least one line of input to execute, so run as follows:
<pre>echo | sed ':loop;s/.*/SPAM/;p;t loop'</pre>
=={{header|Seed7}}==
<
const proc: main is func
Line 1,904:
writeln("SPAM");
end while;
end func;</
=={{header|Self}}==
<syntaxhighlight lang
=={{header|Sidef}}==
<
=={{header|Slate}}==
<syntaxhighlight lang
=={{header|Smalltalk}}==
<
Transcript showCR:'boring stuff'.
] loop
Line 1,930:
[
Transcript showCR:'please press CTRL-c!'.
] doWhile:[true]</
=={{header|SNOBOL4}}==
<
end</
=={{header|SNUSP}}==
<
| | | \M=@@@@+@+++++# \.>.>.>.>./
| | \A=@@+@@@@+++#
| \P=@@+@@+@@+++#
\S=@@+@+@@@+++#</
=={{header|Sparkling}}==
<
print("SPAM");
}</
or
<
print("SPAM");
} while true;</
or
<
printf("SPAM\n");
}</
etc.
Line 1,967:
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
Line 1,982:
waitcnt(_clkfreq + cnt)
ser.stop
cogstop(0)</
=={{header|SPL}}==
<
#.output("SPAM")
<</
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<
--#SET TERMINATOR @
Line 2,003:
END WHILE;
END @
</syntaxhighlight>
Output:
<pre>
Line 2,025:
=={{header|Standard ML}}==
<
print "SPAM\n";</
or
<
fun inf_loop () = (
print "SPAM\n";
Line 2,037:
in
inf_loop ()
end</
Seen like this it looks like the "too much functional" danger when a "while" loop looks far simpler, but the functional loop may be useful to provide data to the next loop without using mutable variable.
Line 2,043:
=={{header|Stata}}==
<
display "SPAM"
}</
=== Mata ===
<
Also possible with a '''[https://www.stata.com/help.cgi?m2_for for]''' loop, but unlike C, the middle expression is not optional:
<
=={{header|Swift}}==
<
println("SPAM")
}</
=={{header|SystemVerilog}}==
<
initial forever $display("SPAM");
endprogram
</syntaxhighlight>
=={{header|Tailspin}}==
<
1 -> \(
<> 'SPAM$#10;' -> !OUT::write
1 -> #
\) -> !VOID
</syntaxhighlight>
=={{header|Tcl}}==
<
puts SPAM
}
Line 2,081:
for {} 1 {} {
puts SPAM
}</
=={{header|TI-83 BASIC}}==
Line 2,087:
There are a few ways to achieve this in TI-83 BASIC
<
:Lbl 1
:Disp "SPAM
:Goto 1
</syntaxhighlight>
Another way is by using a While loop
<
:While 1
:Disp "SPAM
:End
</syntaxhighlight>
=={{header|TI-89 BASIC}}==
<
Disp "SPAM"
EndLoop</
=={{header|TorqueScript}}==
<
echo("SPAM");</
=={{header|Transact-SQL}}==
<
PRINT "SPAM"
END</
=={{header|Trith}}==
<
=={{header|TUSCRIPT}}==
TUSCRIPT has no infinite loop. 999999999 loops are the limit.
<
$$ MODE TUSCRIPT
LOOP/999999999
print "spam"
ENDLOOP
</syntaxhighlight>
=={{header|UNIX Shell}}==
Line 2,133:
Use any of these loops:
<
<
<
{{works with|bash}}
Line 2,143:
{{works with|zsh}}
<
==={{header|C Shell}}===
<
echo SPAM
end</
==={{header|es}}===
<syntaxhighlight lang
=={{header|UnixPipes}}==
<syntaxhighlight lang
=={{header|Unlambda}}==
<
=={{header|Ursa}}==
{{trans|Python}}
<
out "SPAM" endl console
end while</
=={{header|V}}==
<
'SPAM' puts
] while</
=={{header|Vala}}==
<
<
<
=={{header|VAX Assembly}}==
<
4D415053 8F DD 0002 2 pushl #^a"SPAM" ;string on stack
5E DD 0008 3 pushl sp ;reference to string
Line 2,185:
F5 11 0015 8 brb loop ;forever
0017 9
0017 10 .end main</
=={{header|VBA}}==
<
Debug.Print "SPAM"
Loop</
=={{header|VBScript}}==
<
WScript.Echo("SPAM")
Loop</
=={{header|Vedit macro language}}==
<
Message("Spam\n")
}</
or:
<
Message("Spam\n")
} while (1)</
or:
<
Message("Spam\n")
}</
"Nearly infinite" loop can be done by using constant ALL (=1073741824) as repeat count:
<
Message("Spam\n")
}</
=={{header|Visual Basic}}==
<
Debug.Print("SPAM")
Loop</
=={{header|Visual Basic .NET}}==
'''Platform:''' [[.NET]]
{{works with|Visual Basic .NET|9.0+}}
<
Console.WriteLine("SPAM")
Loop</
=={{header|Vlang}}==
<
for {
print("SPAM\n")
}
}</
=={{header|Wart}}==
<
prn "spam"</
=={{header|Wee Basic}}==
<
while loop=1
print 1 "SPAM"
wend
end</
=={{header|Whenever}}==
<
1 print("SPAM");
1;
</syntaxhighlight>
=={{header|Wren}}==
<
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
<
section .text
global _start
Line 2,272:
msg db "SPAM",0xa
len equ $-msg
</syntaxhighlight>
=={{header|XLISP}}==
It is of course possible to use a <code>WHILE</code> loop with a condition that will always evaluate to true:
<
(while t
(display "SPAM")
(newline) ) )</
Although this idiom is very common (in many programming languages), however, it feels a bit like a misuse of a looping construct that is meant to be conditional. If an unconditional jump is really what we want, then that is what we have <tt>goto</tt> for; or rather, in XLISP we do not have <tt>goto</tt> (in so many words) but we can achieve the effect of it using tail recursion.
<
(display "SPAM")
(newline)
(keep-printing-spam) )</
=={{header|XPL0}}==
<
loop Text(0, "SPAM
")</
=={{header|Z80 Assembly}}==
Line 2,295:
Using the Amstrad CPC firmware:
<
txt_output: equ $bb5a
Line 2,308:
jr print
spam: defm "SPAM\r\n\0"</
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
pub fn main() !void {
Line 2,317:
while (true) try stdout_wr.writeAll("SPAM\n");
}
</syntaxhighlight>
=={{header|zkl}}==
<
while(True){ println("SPAM") }
foreach _ in ([0..]){ println("SPAM") }
[0..].pump(Console.println,T(Void,"SPAM"));
[0..].pump(fcn{ println("SPAM") });
fcn{ println("SPAM"); return(self.fcn()) }(); // tail recursive lambda</
{{omit from|GUISS}}
Line 2,330:
=={{header|Zoomscript}}==
For typing:
<
loop = 1
while ne loop 0
print "SPAM"
println
endwhile</
For importing:
|