Loops/Infinite: Difference between revisions
no edit summary
m (added emacs lisp entry) |
No edit summary |
||
(146 intermediate revisions by 78 users not shown) | |||
Line 4:
;Task:
Print out <big> '''SPAM''' </big> followed by a ''newline'' in an infinite loop.
;Related tasks:
* [[Loop over multiple arrays simultaneously]]
* [[Loops/Break]]
* [[Loops/Continue]]
* [[Loops/Do-while]]
* [[Loops/Downward for]]
* [[Loops/For]]
* [[Loops/For with a specified step]]
* [[Loops/Foreach]]
* [[Loops/Increment loop index within loop body]]
* [[Loops/Infinite]]
* [[Loops/N plus one half]]
* [[Loops/Nested]]
* [[Loops/While]]
* [[Loops/with multiple ranges]]
* [[Loops/Wrong ranges]]
<br><br>
=={{header|11l}}==
<syntaxhighlight lang="11l">L
print(‘SPAM’)</syntaxhighlight>
=={{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 25 ⟶ 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 44 ⟶ 66:
BEQ InfiniteLoop
MSG .byte "SPAM", $0A</
=={{header|6800 Assembly}}==
<syntaxhighlight lang="text"> .cr 6800
.tf spam6800.obj,AP1
.lf spam6800
Line 77 ⟶ 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.
<syntaxhighlight lang="68000devpac">doSPAM:
LEA Message,A0
JSR PrintString
JMP doSPAM
Message:
DC.B "SPAM",13,10,0
EVEN</syntaxhighlight>
=={{header|8086 Assembly}}==
{{works with|https://www.dosbox.com DOSBox}}
===Loading Immediates===
<syntaxhighlight lang="asm">Spam:
mov ah,02h
mov dl,'S' ;VASM replaces a character in single quotes with its ascii equivalent
int 21h ;Print Char routine
mov dl,'P'
int 21h
mov dl, 'A'
int 21h
mov dl, 'M'
int 21h
mov dl,13 ;Carriage Return
int 21h
mov dl,10 ;New Line
int 21h
jmp Spam</syntaxhighlight>
===Loading From A Data Source===
<syntaxhighlight lang="asm">mov ah, 02h ;prep int 21h for printing to screen
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
cld ;clear the direction flag, this makes commands like "lodsb" auto-increment
SpamOuter:
mov si, offset SpamMessage ;load the address of SpamMessage into the source index
SpamInner:
lodsb ;mov al,[ds:si] and increment si by 1.
cmp al,0 ;is this the terminator?
jz SpamOuter ;point si to the beginning of the message again
mov dl,al ;the DOS interrupt for printing requires the desired character to be in DL
int 21h ;print the chosen character to the screen
jmp SpamInner
SpamMessage db "SPAM",13,10,0</syntaxhighlight>
=={{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 */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessage: .asciz "SPAM\n"
/*********************************/
/* code section */
/*********************************/
.text
.global main
main:
loop:
ldr x0,qAdrszMessage
bl affichageMess
b loop
qAdrszMessage: .quad szMessage
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* 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!}}==
<syntaxhighlight lang="action!">PROC Main()
DO
PrintE("SPAM")
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Infinite.png Screenshot from Atari 8-bit computer]
<pre>
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
...
</pre>
=={{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}}==
{{trans|ALGOL W}}
<br>
'''Based on the 1962 Revised Repport on ALGOL''':
'''begin'''
'''integer''' i;
'''for''' i:=1 '''step''' 0 '''until''' 2 '''do'''
outtext("spam")
'''end'''
{{works with|ALGOL 60|OS/360}}
<syntaxhighlight lang="algol60">'BEGIN' 'COMMENT' Loops/Infinite - Algol60 - 23/06/2018;
'INTEGER' I;
'FOR' I := 1 'STEP' 0 'UNTIL' 2 'DO'
OUTSTRING(1,'('SPAM')')
'END'</syntaxhighlight>
=={{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 155 ⟶ 310:
message:
.asciz "SPAM\n"
</syntaxhighlight>
=={{header|ArnoldC}}==
<syntaxhighlight lang="arnoldc">IT'S SHOWTIME
STICK AROUND @NO PROBLEMO
TALK TO THE HAND "SPAM"
CHILL
YOU HAVE BEEN TERMINATED</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">while [true] [
print "SPAM"
]</syntaxhighlight>
=={{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}}
{{works with|Commodore BASIC}}
{{works with|Tiny BASIC}}
{{works with|ZX Spectrum Basic}}
The most intuitive method is to use the <code>GOTO</code> statement.
<syntaxhighlight lang="gwbasic">10 print "SPAM"
20 goto 10</syntaxhighlight>
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:
<pre>ready.
new
ready.
10 print "spam! ";:gosub 10
run
spam! spam! spam! spam! spam! spam! spam
! spam! spam! spam! spam! spam! spam! sp
am! spam! spam! spam! spam! spam! spam!
spam! spam! spam! spam! spam! spam!
?out of memory error in 10
ready.
█</pre>
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.
<syntaxhighlight lang="gwbasic">10 clr:print "Commodore Spam! ";:gosub 10</syntaxhighlight>
<syntaxhighlight lang="gwbasic">10 clear : print "Apple Spam! ";: gosub 10</syntaxhighlight>
Rather than a <code>GOTO</code>, instead we can use a <code>FOR... NEXT</code> statement:
<syntaxhighlight lang="gwbasic">10 for i = 1 to 10 step 0 : rem A zero step makes the loop infinite
20 print "SPAM";
30 next i</syntaxhighlight>
In most cases, we can also call the <code>RUN</code> command from within the program.
<syntaxhighlight lang="gwbasic">10 print "Spam! ";
20 run</syntaxhighlight>
<code>IF... THEN</code> has an implied <code>GOTO</code> on some BASICs...
<syntaxhighlight lang="gwbasic">10 print "SPAM SPAM! ";:if 1 then 10</syntaxhighlight>
==={{header|Applesoft BASIC}}===
<
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">while true
print "SPAM"
end while</syntaxhighlight>
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 while 1
20 print "SPAM"
30 wend</syntaxhighlight>
==={{header|Commodore BASIC}}===
In addition to the general examples listed above for [[#BASIC|BASIC]], there is a trick to get a Commodore BASIC program to endlessly loop its listing. All of the lines of code are a linked list in RAM. The trick is accomplished by modifying the pointer to the next line, which is recorded at the very start of each tokenized BASIC line. Instead of it pointing to the next line, you can make it point to a previous line, or itself. This will affect execution when any <code>GOTO</code> or <code>GOSUB</code> needs to reference any line number '''after''' the affected line, since the line search will be corrupted (and endless...)
For example, on the Commodore 64, BASIC program storage begins at $0800 (2048) with a NULL byte, the first line begins at $0801 with the little-endian pointer to the memory address that begins the next line. After entering the short program, <code>POKE</code> a 1 into the low byte portion of the pointer (location $0801) causing complete pointer value to be $0801... pointing to itself. Then run or list the program for endless looping fun.
Other similarly structured BASICs based on the early Microsoft BASIC (where the <code>LIST</code> routine follows the linked list pointers) can be manipulated in the same manner if it is known where BASIC program memory starts.
<pre>ready.
10 rem there is way too much spam in this program!
20 print "spam!!";:goto 10
poke 2049,1
ready.
run
spam!!spam!!spam!!spam!!spam!!spam!!spam!!spam!!
spam!!spam!!spam!!spam!!spam!!spam!!spam!!spam!!
spam!!spam!!spam!!spam!!spam!!spam!!spam!!spam!!
spam!!spam!!spam!!spam!!spam!!spam!!spam!!spam!!
spam!!spam!!spam!!spam!!spam!!spam!!spam!!spam!!
break in 10
ready.
list
10 rem there is way too much spam in this program!
10 rem there is way too much spam in this program!
10 rem there is way too much spam in this program!
10 rem there is way too much spam in this program!
10 rem there is way too much spam in this program!
10 rem there is way too much spam in this program!
break
ready.
█</pre>
==={{header|Craft Basic}}===
<syntaxhighlight lang="text">
do
print "SPAM"
loop
</syntaxhighlight>
==={{header|GW-BASIC}}===
{{works with|PC-BASIC}}
<syntaxhighlight lang="qbasic">10 WHILE 1
20 PRINT "SPAM"
30 WEND</syntaxhighlight>
Also
<syntaxhighlight lang="qbasic">10 PRINT "SPAM"
20 GOTO 10</syntaxhighlight>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 DO
110 PRINT "SPAM"
120 LOOP</syntaxhighlight>
==={{header|MSX Basic}}===
<syntaxhighlight lang="qbasic">10 FOR I = 1 TO 10 STEP 0
20 PRINT "SPAM"
30 NEXT I</syntaxhighlight>
Also
<syntaxhighlight lang="qbasic">10 PRINT "SPAM"
20 GOTO 10</syntaxhighlight>
==={{header|QB64}}===
<syntaxhighlight lang="qb64">'Using Do loop
Do 'Alternatively this could have a conditional, "Do While 1"
Print "SPAM"
Loop
'Using While loop
While 1
Print "SPAM"
Wend</syntaxhighlight>
==={{header|Quite BASIC}}===
<syntaxhighlight lang="qbasic">10 print "SPAM"
20 goto 10</syntaxhighlight>
==={{Header|Tiny BASIC}}===
<syntaxhighlight lang="qbasic"> 10 PRINT "SPAM"
GOTO 10</syntaxhighlight>
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">DO
PRINT "SPAM"
LOOP
END</syntaxhighlight>
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">do
print "SPAM"
loop</syntaxhighlight>
O también
<syntaxhighlight lang="yabasic">while true
print "SPAM"
wend</syntaxhighlight>
=={{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}}==
<syntaxhighlight lang="bcpl">get "libhdr"
let start() be writes("SPAM*N") repeat</syntaxhighlight>
=={{header|beeswax}}==
<
bN`M`<</
=={{header|Befunge}}==
Because the 2-D code space is toroidal, all loops are infinite
unless explicitly stopped with '''@'''.
<
=={{header|
Adding "SPAM\n" to the BLC8 cycle program generated from https://github.com/tromp/AIT/blob/master/lists/cycle.lam
gives the 16 byte program
<pre>11 a1 72 34 00 2d e5 e7 ef b3 40 53 50 41 4d 0a</pre>
=={{header|blz}}==
<syntaxhighlight lang="blz">while true
print("SPAM")
end</syntaxhighlight>
=={{header|bootBASIC}}==
Using <code>goto</code>:
<syntaxhighlight lang="bootbasic">10 print "SPAM"
20 goto 10</syntaxhighlight>
Using <code>run</code>:
<syntaxhighlight lang="bootbasic">10 print "SPAM"
20 run</syntaxhighlight>
=={{header|BQN}}==
The main way of performing an infinite loop in BQN is using recursion.
<syntaxhighlight lang="bqn">{𝕊 •Out 𝕩}"SPAM"</syntaxhighlight>
will likely end in a stack overflow.
=={{header|Bracmat}}==
<syntaxhighlight lang
=={{header|Brainf***}}==
Optimized for code size:
<syntaxhighlight lang="bf">++++++++++[->++++++>++++++++>+<<<]>+++++>
[+++.---.<.>---.+++>.<]</syntaxhighlight>
Optimized for execution speed:
<syntaxhighlight lang="bf">10++++++++++
[-> 8++++++++ > 8++++++++ > 6++++++ > 8++++++++ > 1+ <<<<<]>
83+++ > 80 > 65+++++ > 77--- <<<
[.>.>.>.>.<<<<]</syntaxhighlight>
=={{header|Brat}}==
<
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/String .
main [spam spam]
spam ["SPAM\n" ++ (0 0)]
</syntaxhighlight>
=={{header|C}}==
<
or
<
or
<
or
<
or
<syntaxhighlight lang="c">
spam: puts("SPAM");
goto spam;
</syntaxhighlight>
=={{header|
<syntaxhighlight lang="csharp">while (true)
{
Console.WriteLine("SPAM");
}</syntaxhighlight>
=={{header|C++}}==
{{trans|C}}
<
std::cout << "SPAM\n"
or
<
std::cout << "SPAM\n"
or
<
std::cout << "SPAM\n"
while (true);</
=={{header|
<syntaxhighlight lang="c3">while(1) io::printn("SPAM");</syntaxhighlight>
or
<syntaxhighlight lang="c3">for(;;) io::printn("SPAM");</syntaxhighlight>
or
<syntaxhighlight lang="c3">do { io::printn("SPAM"); } while(1);</syntaxhighlight>
or
<syntaxhighlight lang="c3">switch (1)
{
case 1:
io::printn("SPAM");
nextcase 1;
}
</syntaxhighlight>
=={{header|Chapel}}==
<
=={{header|
<syntaxhighlight lang="text">
while(true) <<<"SPAM">>>;
</syntaxhighlight>
=={{header|Clojure}}==
<
=={{header|COBOL}}==
<
PROGRAM-ID. Spam.
Line 319 ⟶ 673:
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}}==
This will result in a JRun Servlet Error and heap dump.
With tags:
<syntaxhighlight lang="cfm"><cfloop condition = "true NEQ false">
SPAM
</cfloop></syntaxhighlight>
With script:
<syntaxhighlight lang="cfm"><cfscript>
while( true != false )
{
writeOutput( "SPAM" );
}
</cfscript></syntaxhighlight>
=={{header|Comal}}==
<
PRINT "SPAM"
ENDLOOP</
=={{header|Common Lisp}}==
<
=== Using DO ===
<syntaxhighlight lang="lisp">
(do () ; Not initialization
(nil) ; Not break condition
(print "SPAM")) ; On every loop as requested
</syntaxhighlight>
{{out}}
<pre>
"SPAM"
...
</pre>
=={{header|Corescript}}==
<syntaxhighlight lang="corescript">
:top
print Spam!
goto top
</syntaxhighlight>
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
loop
print("Spam\n");
end loop;</syntaxhighlight>
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">loop do
puts "SPAM"
end</syntaxhighlight>
Using <code>while</code>/<code>until</code>:
<syntaxhighlight lang="crystal">while true
puts "SPAM"
end</syntaxhighlight>
<syntaxhighlight lang="crystal">until false
puts "SPAM"
end</syntaxhighlight>
Using an infinite range:
<syntaxhighlight lang="crystal">(0..).each do
puts "SPAM"
end</syntaxhighlight>
=={{header|D}}==
Some common ways to create an infinite printing loop:
<
void main() {
while (true)
writeln("SPAM");
}</
<
void main() {
Line 351 ⟶ 764:
writeln("SPAM");
while (true);
}</
<
void main() {
for ( ; ; )
writeln("SPAM");
}</
<
void main() {
Line 366 ⟶ 779:
writeln("SPAM");
goto LOOP;
}</
=={{header|Dart}}==
<syntaxhighlight lang="text">
main() {
while(true) {
Line 375 ⟶ 788:
}
}
</syntaxhighlight>
=={{header|dc}}==
<
]P dx]dx</
This loop is a tail-recursive function.
Line 385 ⟶ 798:
the outer ''dx'' makes the first call,
and the inner ''dx'' makes each recursive call.
=={{header|DCL}}==
<
$ write sys$output "SPAM"
$ goto loop</
=={{header|Delphi}}==
''See [[#Pascal|Pascal]]''
=={{header|DIBOL-11}}==
<syntaxhighlight lang="DIBOL-11">
START ;Infinite Loop
RECORD SPAM
, A4, 'SPAM'
PROC
XCALL FLAGS (0007000000,1) ;Suppress STOP message
OPEN(8,O,'TT:')
LOOP,
WRITES(8,SPAM)
GOTO LOOP
END
</syntaxhighlight>
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec main() void:
while true do
writeln("SPAM")
od
corp</syntaxhighlight>
=={{header|DWScript}}==
<
PrintLn('SPAM');</
=={{header|Dyalect}}==
<syntaxhighlight lang="dyalect">while true {
print("SPAM")
}</syntaxhighlight>
=={{header|Déjà Vu}}==
<syntaxhighlight lang="dejavu">while true:
!print "SPAM"</syntaxhighlight>
Infinite recursion thanks to tail calls:
<syntaxhighlight lang="dejavu">labda:
!print "SPAM"
recurse
call</syntaxhighlight>
=={{header|E}}==
<
println("SPAM")
}</
<
println("SPAM")
f <- ()
}
f <- ()</
The difference between these is that in the second,
other activities can be interleaved with the loop;
in the first, no other processing will occur in this vat.
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
while 1 = 1
print "SPAM"
.
</syntaxhighlight>
=={{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 458 ⟶ 908:
[ 17 ] PF
EZPF</
=={{header|Ela}}==
Line 464 ⟶ 914:
===Direct Approach===
<
loop () = do
Line 470 ⟶ 920:
loop ()
loop () ::: IO</
===Non-strict version===
<
xs = "SPAM"::xs
Line 483 ⟶ 933:
takeit (num - 1) xs
_ = takeit 10 xs ::: IO</
=={{header|Elena}}==
ELENA 6.x:
<syntaxhighlight lang="elena">public program()
{
while (true)
console
}</syntaxhighlight>
=={{header|Elixir}}==
<
def infinite do
IO.puts "SPAM"
Line 502 ⟶ 953:
end
Loops.infinite</
or
<
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(while t
(message "SPAM"))</syntaxhighlight>
=={{header|EMal}}==
<syntaxhighlight lang="emal">
for ever
writeLine("SPAM")
end
</syntaxhighlight>
=={{header|Erlang}}==
<
-module (main).
-export ([main/0]).
Line 514 ⟶ 977:
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 549 ⟶ 1,004:
printfn "SPAM"
forever ()
</syntaxhighlight>
=={{header|Factor}}==
Tail recursion:
<
Looping combinators:
<syntaxhighlight lang="factor">[ "SPAM" print t ] loop</syntaxhighlight>
<syntaxhighlight lang="factor">USE: combinators.extras
[ "SPAM" print ] forever</syntaxhighlight>
=={{header|FALSE}}==
<
"]#</
=={{header|Fantom}}==
<
class Main
{
Line 572 ⟶ 1,031:
}
}
</syntaxhighlight>
=={{header|Fermat}}==
<syntaxhighlight lang="fermat">while 1 do !!'SPAM'; od</syntaxhighlight>
=={{header|Fish}}==
<syntaxhighlight lang="fish">a"MAPS"ooooo</syntaxhighlight>
=={{header|Forth}}==
<
=={{header|Fortran}}==
FORTRAN 77
<
10 WRITE(*,*) 'SPAM'
GO TO 10
END
</syntaxhighlight>
Fortran 90
<
program spam
implicit none
Line 593 ⟶ 1,058:
end do
end program spam
</syntaxhighlight>
=={{header|Fortress}}==
<syntaxhighlight lang="fortress">
component loops_infinite
export Executable
run() = while true do
println("SPAM")
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
while 1
NSLog(@"SPAM")
wend
dispatchend
HandleEvents</syntaxhighlight>
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=e63dcdc939f8a7dcfd3194d884f8d4a5 Click this link to run this code]'''
<
Do
Line 626 ⟶ 1,103:
Loop
End</
=={{header|GAP}}==
<
Print("SPAM\n");
od;</
=={{header|GB BASIC}}==
<syntaxhighlight lang="gb basic">10 print "SPAM"
20 goto10</syntaxhighlight>
=={{header|GDScript}}==
{{works with|Godot|4.0.1}}
<syntaxhighlight lang="gdscript">
extends MainLoop
func _process(_delta: float) -> bool:
print("SPAM")
return false # _process loops until true is returned
</syntaxhighlight>
=={{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.
<syntaxhighlight lang="glovepie">debug = "SPAM"</syntaxhighlight>
=={{header|GML}}==
<
show_message("SPAM")</
=={{header|Go}}==
<
import "fmt"
func main() {
for {
fmt.Printf("SPAM\n")
}
}</
=={{header|Groovy}}==
<
println 'SPAM'
}</
=={{header|Halon}}==
<
echo "SPAM";
}</
or (due to optimizations, these are equally fast)
<
echo "SPAM";
}</
=={{header|Hare}}==
<syntaxhighlight lang="hare">use fmt;
export fn main() void = {
for (true) {
fmt::println("SPAM")!;
};
};</syntaxhighlight>
=={{header|Haskell}}==
<
or
<
fix (putStrLn "SPAM" >>) </
=={{header|Haxe}}==
<syntaxhighlight lang="haxe">while (true)
Sys.println("SPAM");</syntaxhighlight>
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">while true; println "SPAM"; endwhile</syntaxhighlight>
=={{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 689 ⟶ 1,205:
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 707 ⟶ 1,223:
DO READ OUT ,1
(2) DO ,1 SUB #1 <- #134
(1) PLEASE ABSTAIN FROM (2)</
=={{header|Io}}==
<
=={{header|J}}==
<syntaxhighlight lang
Alternatively,
<
This second implementation relies on numeric inaccuracies in IEEE floating point notation.
Line 725 ⟶ 1,241:
=={{header|Java}}==
<syntaxhighlight lang="java">
while
</syntaxhighlight>
<syntaxhighlight lang="java">
for
</syntaxhighlight>
=={{header|JavaScript}}==
<
<
=={{header|Joy}}==
<
["SPAM\n" putchars] loop.</syntaxhighlight>
=={{header|jq}}==
<
{{Out}}
"SPAM"
Line 750 ⟶ 1,265:
To suppress the quotation marks, invoke jq with the -r option.
=={{header|Jsish}}==
<syntaxhighlight lang="javascript">for (;;) puts('SPAM');</syntaxhighlight>
=={{header|Julia}}==
<syntaxhighlight lang="julia">
while true
println("SPAM")
end
</syntaxhighlight>
{{out}}
<pre>
Line 770 ⟶ 1,288:
=={{header|K}}==
<
=={{header|Kotlin}}==
<
fun main(args: Array<String>) {
while (true) println("SPAM")
}</
=={{header|LabVIEW}}==
{{VI solution|LabVIEW_Loops_Infinite.png}}
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def loops_infinite
{lambda {}
{if true then SPAM{br} {loops_infinite} else never}}}
-> loops_infinite
{loops_infinite}
-> SPAM forever...
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
loop {
fn.println(SPAM)
}
</syntaxhighlight>
=={{header|Lang5}}==
<
=={{header|Lasso}}==
<
while(1 > 0) => {^
'SPAM\r'
^}</
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">procedure:
label spam
display "SPAM" lf
goto spam
</syntaxhighlight>
=={{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 816 ⟶ 1,359:
=={{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 841 ⟶ 1,384:
print("SPAM")
until false
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
All loops can stop using Esc or Ctrl+C or Break (the last two open dialog box to stop or continue). Using Escape Off we make Esc not work for breaking execution.
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"
loop
}
Checkit
</syntaxhighlight>
Using a Repeat (or Do) - Always block
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Repeat {
Print "SPAM"
} Always
}
Checkit
</syntaxhighlight>
Printing text rendering using Report.
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
\\ stop in every 2/3 of cosole lines
\\ press spacebar or mouse button to continue
Report Format$("Spam\n")
Loop
}
Checkit
\\ using multiline string, replace report from module above
Report {SPAM
}
</syntaxhighlight>
=={{header|M4}}==
<
spam')
spam</
=={{header|MACRO11}}==
<syntaxhighlight lang="MACRO11">
; Infinte Loop under RT11
.MCALL .PRINT
.EVEN
BEGIN:
LOOP:
.PRINT #SPAM
BR LOOP
SPAM: .ASCIZ /SPAM/
.END BEGIN
</syntaxhighlight>
=={{header|MAD}}==
<syntaxhighlight lang="mad"> VECTOR VALUES SPAM = $4HSPAM*$
LOOP PRINT FORMAT SPAM
TRANSFER TO LOOP
END OF PROGRAM</syntaxhighlight>
=={{header|Make}}==
<
@echo SPAM
$(MAKE)</
=={{header|Malbolge}}==
<syntaxhighlight lang="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>:
<syntaxhighlight lang="melonbasic">Say:"SPAM"
Goto:1</syntaxhighlight>
Using <code>Goto:start</code>:
<syntaxhighlight lang="melonbasic">Say:"SPAM"
Goto:start</syntaxhighlight>
=={{header|Metafont}}==
<
=={{header|Microsoft Small Basic}}==
With <code>While</code>.
<syntaxhighlight lang="microsoftsmallbasic">
While "True"
TextWindow.WriteLine("SPAM")
EndWhile
</syntaxhighlight>
With <code>Goto</code>.
<syntaxhighlight lang="microsoftsmallbasic">
loopStart:
TextWindow.WriteLine("SPAM")
Goto loopStart
</syntaxhighlight>
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">(true) ("SPAM" puts!) while</syntaxhighlight>
=={{header|MIPS Assembly}}==
Thanks to [https://www.chibialiens.com/mips/ Chibialiens.com] for the header/footer, bitmap font, and print routines.
<syntaxhighlight lang="mips">.include "\SrcAll\Header.asm"
.include "\SrcAll\BasicMacros.asm"
.include "\SrcPSX\MemoryMap.asm"
.include "\SrcN64\MemoryMap.asm"
CursorX equ 0x100
CursorY equ 0x101
main:
la a0,MyString
jal PrintString
nop
jal NewLine
nop
j main
nop
MyString:
.byte "SPAM",255,0,0,0 ;the 3 zeroes are padding to ensure proper alignment.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MyFont:
.ifdef buildn64
.incbin "\ResN64\ChibiAkumas.fnt"
.endif
.ifdef buildPSX
.incbin "\ResPSX\ChibiAkumas.fnt"
.endif
.include "\SrcALL\graphics.asm"
.include "..\\SrcAll\monitor.asm"
.include "\SrcN64\Footer.asm"</syntaxhighlight>
{{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}}==
<syntaxhighlight lang="montilang">WHILE TRUE
|SPAM| PRINT .
ENDWHILE</syntaxhighlight>
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}}==
<syntaxhighlight lang="nanoquery">while true
println "SPAM"
end</syntaxhighlight>
=={{header|Nemerle}}==
<
Or, using recursion:
<
{
WriteLine("SPAM");
loop();
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols nobinary
Line 928 ⟶ 1,609:
say 'SPAM'
end spam
</syntaxhighlight>
=={{header|NewLISP}}==
<
=={{header|Nim}}==
<
echo "SPAM"</
=={{header|NS-HUBASIC}}==
Using <code>FOR</code>:
<syntaxhighlight lang="ns-hubasic">10 FOR I=0 TO 1 STEP 0
20 PRINT "SPAM"
30 NEXT</syntaxhighlight>
Using <code>GOTO</code>:
<syntaxhighlight lang="ns-hubasic">10 PRINT "SPAM"
20 GOTO 10</syntaxhighlight>
Using <code>RUN</code>:
<syntaxhighlight lang="ns-hubasic">10 PRINT "SPAM"
20 RUN</syntaxhighlight>
=={{header|Nu}}==
<syntaxhighlight lang="nu">
while true {print SPAM}
</syntaxhighlight>
=={{header|Oberon-2}}==
<
MODULE InfiniteLoop;
IMPORT
Line 947 ⟶ 1,647:
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}}==
<syntaxhighlight lang="scheme">
(let loop ()
(display "SPAM")
(loop))
</syntaxhighlight>
=={{header|OPL}}==
<syntaxhighlight lang="opl">PROC main:
LOCAL loop%
loop%=1
while loop%=1
PRINT "SPAM"
ENDWH
ENDP</syntaxhighlight>
=={{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}}==
<syntaxhighlight lang
print "SPAM\n";
}</syntaxhighlight>
or equivalently
<syntaxhighlight lang="perl">print "SPAM\n" while 1;</syntaxhighlight>
=={{header|Phix}}==
<!--<syntaxhighlight lang="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>
<!--</syntaxhighlight>-->
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/w/index.php?title=Loops/Infinite
by Galileo, 11/2022 #/
true while "SPAM\n" print true endwhile</syntaxhighlight>
=={{header|PHP}}==
<
echo "SPAM\n";</
=={{header|PicoLisp}}==
<
=={{header|Pike}}==
<syntaxhighlight lang
write("SPAM\n");
</syntaxhighlight>
=={{header|PILOT}}==
<
type:SPAM
jump:*TypeSpam</
=={{header|Pixilang}}==
<syntaxhighlight lang="pixilang">start:
fputs("SPAM\n")
go start</syntaxhighlight>
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
do forever;
put list ('SPAM'); put skip;
end;</syntaxhighlight>
=={{header|PL/M}}==
<syntaxhighlight lang="PL/M">
100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
DECLARE SPAM DATA ('SPAM',0DH,0AH,'$');
LOOP: DO;
CALL PRINT( .SPAM );
GO TO LOOP;
END;
EOF
</syntaxhighlight>
=={{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.
<syntaxhighlight lang="plainenglish">To run:
Start up.
Write SPAM forever.
Shut down.
To write SPAM forever:
Write "SPAM" to the console.
Repeat.</syntaxhighlight>
=={{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,079 ⟶ 1,832:
%start spamming!
go</
=={{header|PowerShell}}==
<
"SPAM"
}</
=={{header|Prolog}}==
<
=={{header|Pure Data}}==
Line 1,093 ⟶ 1,846:
Screenshot: https://i.imgur.com/IrwaafZ.png
<
#X obj 17 75 print;
#X msg 17 55 SPAM;
Line 1,100 ⟶ 1,853:
#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,106 ⟶ 1,859:
=={{header|PureBasic}}==
===Repeat/Forever===
<
PrintN("SPAM")
ForEver</
===Goto===
<
PrintN("SPAM")
Goto PrintIt</
=={{header|Python}}==
In Python 2:
<syntaxhighlight lang="python">while 1:
print "SPAM"</syntaxhighlight>
In python 3:
<syntaxhighlight lang="python">while 1:
print("SPAM")</syntaxhighlight>
Note: one can also use: "True" or any other non-false value.
Line 1,123 ⟶ 1,881:
Any non-empty collection or string or non-zero numeric value is considered "True".
However, according to [http://wiki.python.org/moin/PythonSpeed#Takeadvantageofinterpreteroptimizations Python Wiki], for Python versions 2.3+ this variant is optimized by the interpreter and thus is the fastest.
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">[ say "SPAM" cr again ]</syntaxhighlight>
=={{header|R}}==
Line 1,128 ⟶ 1,890:
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,145 ⟶ 1,907:
(for ([i (in-naturals)])
(displayln "SPAM"))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo Star|2010.08}}
<syntaxhighlight lang="raku" line>loop {
say 'SPAM';
}</syntaxhighlight>
In addition, there are various ways of writing lazy, infinite lists in Raku:
<syntaxhighlight lang="raku" line>print "SPAM\n" xx *; # repetition operator
print "SPAM\n", ~* ... *; # sequence operator
map {say "SPAM"}, ^Inf; # upto operator</syntaxhighlight>
=={{header|Rapira}}==
<syntaxhighlight lang="rapira">while 1 do
output: "SPAM"
od</syntaxhighlight>
=={{header|RATFOR}}==
<syntaxhighlight lang="RATFOR">
program loop
while (1==1)
write(*,101)"SPAM"
101 format(A)
end
</syntaxhighlight>
=={{header|REBOL}}==
<
=={{header|Red}}==
<
print "SPAM"
]</
=={{header|ReScript}}==
<syntaxhighlight lang="rescript">while true {
Js.log("SPAM")
}</syntaxhighlight>
or
<syntaxhighlight lang="rescript">let rec inf_loop = () => {
Js.log("SPAM")
inf_loop()
}</syntaxhighlight>
=={{header|Retro}}==
<
=={{header|REXX}}==
===simple===
<
do forever
Line 1,166 ⟶ 1,968:
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,175 ⟶ 1,977:
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,184 ⟶ 1,986:
/*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,192 ⟶ 1,994:
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|
This will display the word '''SPAM''' at the bottom of the screen indefinitely:
<syntaxhighlight lang="robotic">
: "infinite_loop"
* "SPAM"
goto "infinite_loop"
</syntaxhighlight>
=={{header|
Usually in RPL, "printing" an object in RPL means putting it on top of the stack.
In the present case, the loop would not be infinite since sooner or later the stack will overflow.
But if the printer has an infinite paper roll, this will never stop:
≪ "SPAM" '''WHILE''' 1 '''REPEAT''' PR1 '''END''' ≫ EVAL
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">loop {puts "SPAM"}
</syntaxhighlight>
=={{header|Run BASIC}}==
<
while 1
print "Spam"
wend</
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn main() {
loop {
println!("SPAM");
}
}</syntaxhighlight>
=={{header|S-lang}}==
<
=={{header|Salmon}}==
<
"SPAM"!;</
=={{header|Sather}}==
<
main is
loop
Line 1,234 ⟶ 2,049:
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,262 ⟶ 2,077:
=={{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,277 ⟶ 2,092:
writeln("SPAM");
end while;
end func;</
=={{header|Self}}==
<syntaxhighlight lang
=={{header|Sidef}}==
<
=={{header|Slate}}==
<syntaxhighlight lang
=={{header|Smalltalk}}==
<syntaxhighlight lang="smalltalk">[
Transcript showCR:'boring stuff'.
] loop
[true] whileTrue:[
Transcript showCR:'also borinh'.
]
[
Transcript showCR:'poor cpu'.
] doUntil:[false]
[
Transcript showCR:'please press CTRL-c!'.
] doWhile:[true]</syntaxhighlight>
=={{header|SNOBOL4}}==
<
end</
=={{header|SNUSP}}==
<
| | | \M=@@@@+@+++++# \.>.>.>.>./
| | \A=@@+@@@@+++#
| \P=@@+@@+@@+++#
\S=@@+@+@@@+++#</
=={{header|Sparkling}}==
<
print("SPAM");
}</
or
<
print("SPAM");
} while true;</
or
<
printf("SPAM\n");
}</
etc.
=={{header|Spin}}==
{{works with|BST/BSTC}}
{{works with|FastSpin/FlexSpin}}
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<syntaxhighlight lang="spin">con
_clkmode = xtal1 + pll16x
_clkfreq = 80_000_000
obj
ser : "FullDuplexSerial.spin"
pub main
ser.start(31, 30, 0, 115200)
repeat
ser.str(string("SPAM",13,10))
waitcnt(_clkfreq + cnt)
ser.stop
cogstop(0)</syntaxhighlight>
=={{header|SPL}}==
<
#.output("SPAM")
<</
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<syntaxhighlight lang="sql pl">
--#SET TERMINATOR @
SET SERVEROUTPUT ON@
BEGIN
DECLARE I SMALLINT DEFAULT 1;
WHILE (I = I) DO
CALL DBMS_OUTPUT.PUT_LINE('SPAM');
END WHILE;
END @
</syntaxhighlight>
Output:
<pre>
db2 -td@
db2 => SET SERVEROUTPUT ON@
db2 => BEGIN
...
db2 (cont.) => END @
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL20511N There is not enough available space in the "DBMS_OUTPUT" message
buffer. SQLSTATE=54035
SPAM
SPAM
SPAM
SPAM
...
</pre>
=={{header|Standard ML}}==
<
print "SPAM\n";</
or
<
fun inf_loop () = (
print "SPAM\n";
Line 1,339 ⟶ 2,225:
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 1,345 ⟶ 2,231:
=={{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|TailDot}}==
<syntaxhighlight lang="taildot">c,x,SPAM,v,x,j,3</syntaxhighlight>
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
'SPAM$#10;' -> \(
<> $ -> !OUT::write
$ -> #
\) -> !VOID
</syntaxhighlight>
=={{header|Tcl}}==
<
puts SPAM
}
Line 1,381 ⟶ 2,270:
for {} 1 {} {
puts SPAM
}</
=={{header|TI-83 BASIC}}==
Line 1,387 ⟶ 2,276:
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}}==
<syntaxhighlight lang="sql">WHILE 1=1 BEGIN
PRINT "SPAM"
END</syntaxhighlight>
=={{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 1,427 ⟶ 2,322:
Use any of these loops:
<
<
<
{{works with|bash}}
Line 1,437 ⟶ 2,332:
{{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|Uxntal}}==
<syntaxhighlight lang="Uxntal">
|0100
&l ;SPAM <print-str> !&l
@<print-str> ( str* -- )
&while ( -- )
LDAk #18 DEO
INC2 LDAk ?&while
POP2 JMP2r
@SPAM
"SPAM 0a $1</syntaxhighlight>
=={{header|V}}==
<
'SPAM' puts
] while</
=={{header|Vala}}==
<
<
<
=={{header|Vale}}==
{{works with|Vale|0.2.0}}
<syntaxhighlight lang="vale">
import stdlib.*;
exported func main() {
while true {
println("SPAM");
}
}
</syntaxhighlight>
=={{header|VAX Assembly}}==
<syntaxhighlight lang="vax assembly"> 0000 0000 1 .entry main,0
4D415053 8F DD 0002 2 pushl #^a"SPAM" ;string on stack
5E DD 0008 3 pushl sp ;reference to string
04 DD 000A 4 pushl #4 ;+length = descriptor
000C 5 loop:
5E DD 000C 6 pushl sp ;descriptor by reference
00000000'GF 01 FB 000E 7 calls #1, g^lib$put_output ;show message
F5 11 0015 8 brb loop ;forever
0017 9
0017 10 .end main</syntaxhighlight>
=={{header|VBA}}==
<syntaxhighlight lang="vb">Do
Debug.Print "SPAM"
Loop</syntaxhighlight>
=={{header|VBScript}}==
<syntaxhighlight lang="vb">Do
WScript.Echo("SPAM")
Loop</syntaxhighlight>
=={{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|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
for {
print("SPAM\n")
}
}</syntaxhighlight>
=={{header|Wart}}==
<
prn "spam"</
=={{header|Wee Basic}}==
<syntaxhighlight lang="wee basic">let loop=1
while loop=1
print 1 "SPAM"
wend
end</syntaxhighlight>
=={{header|Whenever}}==
<syntaxhighlight lang="whenever">
1 print("SPAM");
1;
</syntaxhighlight>
=={{header|Wren}}==
<syntaxhighlight lang="wren">while (true) System.print("SPAM")</syntaxhighlight>
=={{header|X86 Assembly}}==
{{works with|NASM|Linux}}
<
section .text
global _start
Line 1,518 ⟶ 2,486:
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 1,541 ⟶ 2,509:
Using the Amstrad CPC firmware:
<
txt_output: equ $bb5a
Line 1,554 ⟶ 2,522:
jr print
spam: defm "SPAM\r\n\0"</
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
pub fn main() !void {
const stdout_wr = std.io.getStdOut().writer();
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}}
=={{header|Zoomscript}}==
For typing:
<syntaxhighlight lang="zoomscript">var loop
loop = 1
while ne loop 0
print "SPAM"
println
endwhile</syntaxhighlight>
For importing:
¶0¶var loop¶0¶loop = 1¶0¶while ne loop 0¶1¶print "SPAM"¶1¶println¶0¶endwhile
|