Loops/Infinite

From Rosetta Code
< Loops(Redirected from Loop/Infinite)
Task
Loops/Infinite
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Print out       SPAM       followed by a   newline   in an infinite loop.

Contents

360 Assembly[edit]

This for sure will result in a severe WTO buffer shortage.

 
INFINITE CSECT , this PGM control section
INFINITE AMODE 31 addressing mode 31 bit
INFINITE RMODE ANY loader can load either 24 or 31
BAKR 14,0 stack caller's register contents
LR 12,15 establish base
LA 13,0 no savearea
USING INFINITE,12 base to assembler
LA 10,1 1 in reg 10
LA 11,2 2 in reg 11
LOOP EQU *
CR 10,11 1==2?
BE RETURN Yes, exit.
WTO 'SPAM',ROUTCDE=11 print SPAM to syslog
B LOOP No, check again.
RETURN PR , return to caller
END INFINITE
 

4DOS Batch[edit]

@echo off
do forever
echo SPAM
enddo

6502 Assembly[edit]

Specific OS/hardware routines for printing are left unimplemented.

InfiniteLoop	LDX #0
PrintLoop: LDA MSG,x
JSR PrintAccumulator ;routine not implemented
INX
CPX #5
BNE PrintLoop
BEQ InfiniteLoop
 
MSG .byte "SPAM", $0A

6800 Assembly[edit]

        .cr  6800
.tf spam6800.obj,AP1
.lf spam6800
;=====================================================;
; Infinite SPAM loop for the Motorola 6800  ;
; by barrym 2013-04-10  ;
;-----------------------------------------------------;
; Prints the message "SPAM" repeatedly to an ascii  ;
; terminal (console) connected to a 1970s vintage  ;
; SWTPC 6800 system, which is the target device for ;
; this assembly.  ;
; Many thanks to:  ;
; swtpc.com for hosting Michael Holley's documents! ;
; sbprojects.com for a very nice assembler!  ;
; swtpcemu.com for a very capable emulator!  ;
; reg x is the string pointer  ;
; reg a holds the ascii char to be output  ;
;-----------------------------------------------------;
outeee = $e1d1  ;ROM: console putchar routine
.or $0f00
;-----------------------------------------------------;
main ldx #string  ;Point to the string
bra puts  ; and print it
outs jsr outeee  ;Emit a as ascii
inx  ;Advance the string pointer
puts ldaa ,x  ;Load a string character
bne outs  ;Print it if non-null
bra main  ;else restart
;=====================================================;
string .as "SPAM",#13,#10,#0
.en

8th[edit]

One way:

 
: inf "SPAM\n" . recurse ;
 

Another way:

 
: inf repeat "SPAM\n" . again ;
 

ACL2[edit]

(defun spam ()
(declare (xargs :mode :program))
(if nil
nil
(prog2$ (cw "SPAM~%")
(spam))))

ActionScript[edit]

while (true) {
trace("SPAM");
}

Ada[edit]

loop
Put_Line("SPAM");
end loop;

Aime[edit]

while (1) {
o_text("SPAM\n");
}

ALGOL 68[edit]

DO
printf($"SPAM"l$)
OD

Or the classic "dynamic halt":

loop x:
printf($"SPAM"l$);
loop x

ALGOL W[edit]

begin
for i := 1 step 0 until 2 do write( "SPAM" )
end.

AmigaE[edit]

PROC main()
LOOP
WriteF('SPAM')
ENDLOOP
ENDPROC

AppleScript[edit]

repeat
log "SPAM"
end repeat

ARM Assembly[edit]

 
.global main
 
main:
 
loop:
ldr r0, =message
bl printf
b loop
 
message:
.asciz "SPAM\n"
 

AutoHotkey[edit]

Loop
MsgBox SPAM `n

AWK[edit]

BEGIN {
while(1) {
print "SPAM"
}
}

Axe[edit]

Warning: running this program will cause you to need to reset your calculator, thereby losing any user data stored in RAM.

While 1
Disp "SPAM",i
End

BASIC[edit]

Works with: QuickBasic version 4.5

Old-fashioned syntax:

WHILE 1
PRINT "SPAM"
WEND

Standard BASIC:

DO
PRINT "SPAM"
LOOP

Also

FOR i = 1 TO 10 STEP 0
PRINT "SPAM"
NEXT i
Works with: Applesoft BASIC
Works with: ZX Spectrum Basic
10 PRINT "SPAM"
20 GOTO 10

Rather than a GOTO, instead we can use a FOR statement:

10 FOR l = 1 TO 10 STEP 0: REM A zero step makes the loop infinite
20 PRINT "SPAM"
30 NEXT l

Applesoft BASIC[edit]

FOR I = 0 TO 1 STEP 0 : PRINT "SPAM" : NEXT

Batch File[edit]

Using goto:

@echo off
:loop
echo SPAM
goto loop

Another variant which uses Windows NT's for statement:

Works with: Windows NT version 4 or later
for /l %%x in (1,0,2) do @echo SPAM

This essentially is a counted loop which starts at 1, increments by 0 and stops when the counter reaches 2.

BBC BASIC[edit]

      REPEAT
PRINT "SPAM"
UNTIL FALSE

bc[edit]

while (1) "SPAM
"

Befunge[edit]

Because the 2-D code space is toroidal, all loops are infinite unless explicitly stopped with @.

55+"MAPS",,,,,

Brainf***[edit]

++++++++++[->++++++>++++++++>+<<<]>+++++>
[+++.---.<.>---.+++>.<]

Bracmat[edit]

whl'out$SPAM

Brat[edit]

loop { p "SPAM" }

C[edit]

while(1) puts("SPAM");

or

 for(;;) puts("SPAM");

or

do { puts("SPAM"); } while(1);

or

while(puts("SPAM"));

ChucK[edit]

 
while(true) <<<"SPAM">>>;
 

C++[edit]

Translation of: C
while (true)
std::cout << "SPAM" << std::endl;

or

for (;;)
std::cout << "SPAM" << std::endl;

or

do
std::cout << "SPAM" << std::endl;
while (true);

C#[edit]

while (true)
{
Console.WriteLine("SPAM");
}

Chapel[edit]

while true do writeln("SPAM");

ColdFusion[edit]

This will result in a JRun Servlet Error and heap dump.

With tags:

<cfloop condition = "true NEQ false">
SPAM
</cfloop>

With script:

<cfscript>
while( true != false )
{
writeOutput( "SPAM" );
}
</cfscript>

Clojure[edit]

(loop [] (println "SPAM") (recur))

COBOL[edit]

       IDENTIFICATION DIVISION.
PROGRAM-ID. Spam.
 
PROCEDURE DIVISION.
PERFORM UNTIL 1 <> 1
DISPLAY "SPAM"
END-PERFORM
 
GOBACK
.

OpenCOBOL supports a FOREVER clause for PERFORM which will have the same effect.

CoffeeScript[edit]

loop
console.log 'SPAM'
 


Comal[edit]

LOOP
PRINT "SPAM"
ENDLOOP

Common Lisp[edit]

(loop (write-line "SPAM"))

D[edit]

Some common ways to create an infinite printing loop:

import std.stdio;
 
void main() {
while (true)
writeln("SPAM");
}
import std.stdio;
 
void main() {
do
writeln("SPAM");
while (true);
}
import std.stdio;
 
void main() {
for ( ; ; )
writeln("SPAM");
}
import std.stdio;
 
void main() {
LOOP:
writeln("SPAM");
goto LOOP;
}

dc[edit]

[[SPAM
]P dx]dx

This loop is a tail-recursive function. The program pushes the function on the stack, the outer dx makes the first call, and the inner dx makes each recursive call.

DCL[edit]

$ loop:
$ write sys$output "SPAM"
$ goto loop

Déjà Vu[edit]

while true:
!print "SPAM"

Infinite recursion thanks to tail calls:

labda:
!print "SPAM"
recurse
call

Delphi[edit]

while True do Writeln('SPAM');

DWScript[edit]

while True do
PrintLn('SPAM');

E[edit]

while (true) {
println("SPAM")
}
def f() {
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.

Ela[edit]

Direct Approach[edit]

open monad io
 
loop () = do
putStrLn "SPAM"
loop ()
 
loop () ::: IO

Non-strict version[edit]

open monad io
 
xs = "SPAM"::xs
 
takeit 0 _ = do return ()
takeit num (x::xs) = do
putStrLn x
takeit (num - 1) xs
 
_ = takeit 10 xs ::: IO

Elena[edit]

#import system.
 
#symbol program =
[
#loop true?
[
console writeLine:"span".
].
].
 

Elixir[edit]

defmodule Loops do
def infinite do
IO.puts "SPAM"
infinite
end
end
 
Loops.infinite

or

Stream.cycle(["SPAM"]) |> Enum.each(&IO.puts &1)

Erlang[edit]

 
-module (main).
-export ([main/0]).
 
main() ->
io:fwrite( "SPAM~n" ),
main().
 


ERRE[edit]

 
LOOP
PRINT("SPAM")
END LOOP
 

You can use also WHILE TRUE..END WHILE or REPEAT...UNTIL FALSE loops.

Euphoria[edit]

 
while 1 do
puts(1, "SPAM\n")
end while
 

F#[edit]

 
// Imperative Solution
while true do
printfn "SPAM"
 
// Functional solution
let rec forever () : unit =
printfn "SPAM"
forever ()
 

Factor[edit]

: spam ( -- ) "SPAM" print spam ;
: spam ( -- ) [ "SPAM" print t ] loop ;

FALSE[edit]

[1]["SPAM
"]#

Fantom[edit]

 
class Main
{
public static Void main ()
{
while (true)
{
echo ("SPAM")
}
}
}
 

Forth[edit]

: email   begin ." SPAM" cr again ;

Fortran[edit]

FORTRAN 77

 
10 WRITE(*,*) 'SPAM'
GO TO 10
END
 

Fortran 90

 
program spam
implicit none
do
write(*,*) 'SPAM'
end do
end program spam
 

Frink[edit]

 
while true
println["SPAM"]
 

FutureBasic[edit]

Loop de loop -- whose great idea was this?

 
include "ConsoleWindow"
 
while 1
print "Spam"
wend
 


GAP[edit]

while true do
Print("SPAM\n");
od;

GML[edit]

while(1)
show_message("SPAM")

Go[edit]

package main
import "fmt"
func main() {
for {
fmt.Printf("SPAM\n")
}
}

Groovy[edit]

while (true) {
println 'SPAM'
}

Haskell[edit]

forever (putStrLn "SPAM")

or

import Control.Monad.Fix (fix)
fix (putStrLn "SPAM" >>)

HicEst[edit]

DO i = 1, 1E20 ! for i with 16 or more digits:  i == i + 1 == loop infinite
WRITE() "SPAM"
ENDDO

Icon and Unicon[edit]

There are several ways to write infinite loops in Icon. The most straightforward would be with repeat.

procedure main()
repeat write("SPAM")
end

Alternately one could use one of these:

until &fail do write("SPAM")   # always fails, needs succeed to break
...
while write("SPAM") # always succeeds, needs failure to break
...
every write(|"SPAM") # generator always succeeds, needs failure to break
...
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

IDL[edit]

while 1 do print,'SPAM'

Intercal[edit]

Assuming Turing Text I/O with 8-bit ASCII-compatible character set, using COME FROM:

       NOTE THIS IS INTERCAL
PLEASE ,1 <- #5
DO ,1 SUB #1 <- #54
DO ,1 SUB #2 <- #192
DO ,1 SUB #3 <- #136
PLEASE ,1 SUB #4 <- #208
DO ,1 SUB #5 <- #98
DO COME FROM (1)
DO READ OUT ,1
(2) DO ,1 SUB #1 <- #134
(1) PLEASE ABSTAIN FROM (2)

Io[edit]

loop("SPAM" println)

J[edit]

(-[smoutput bind 'SPAM')^:_(1)

Alternatively,

smoutput bind 'SPAM'^:1e99 ''

This second implementation relies on numeric inaccuracies in IEEE floating point notation. For example, 1+1e98 is exactly equal to 1e98. That said, 1e98 iterations would still be significantly longer than the practical life of any machine anyone would care to dedicate to this task.

Java[edit]

while(true){
System.out.println("SPAM");
}
for(;;){
System.out.println("SPAM");
}

JavaScript[edit]

for (;;) console.log("SPAM");
while (true) console.log("SPAM");

Joy[edit]

DEFINE loop == [true []] dip while.
 
["SPAM\n" putchars] loop.

jq[edit]

recurse("SPAM")
Output:
"SPAM"
"SPAM"
...

To suppress the quotation marks, invoke jq with the -r option.

Julia[edit]

 
while true
println("SPAM")
end
 
Output:
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM

and so on until ^C

K[edit]

   while[1; `0:"SPAM\n"]

LabVIEW[edit]

This image is a VI Snippet, an executable image of LabVIEW code. The LabVIEW version is shown on the top-right hand corner. You can download it, then drag-and-drop it onto the LabVIEW block diagram from a file browser, and it will appear as runnable, editable code.
LabVIEW Loops Infinite.png

Lang5[edit]

do "SPAM\n" . loop

Lasso[edit]

// not wise to run this!
while(1 > 0) => {^
'SPAM\r'
^}

Liberty BASIC[edit]

<CTRL><Break> is used to terminate such loops.

 
while 1
print "SPAM"
wend
end
 

Lily[edit]

 
while 1: print("SPAM\n")
 

Lisaac[edit]

{ "SPAM\n".print; }.endless_loop;

LiveCode[edit]

repeat forever
put "SPAM" & return
end repeat

[edit]

forever [print "SPAM]

LOLCODE[edit]

HAI
CAN HAS STDIO?
IM IN YR LOOP
VISIBLE "SPAM"
IM OUTTA YR LOOP
KTHXBYE

Lua[edit]

 
while true do
print("SPAM")
end
 
--Another solution
repeat
print("SPAM")
until false
 

M4[edit]

define(`spam',`SPAM
spam')
spam

Make[edit]

spam:
@echo SPAM
$(MAKE)

Maple[edit]

 
> do print(SPAM) end;
 

Mathematica / Wolfram Language[edit]

While[True,
Print@"SPAM";
]

MATLAB / Octave[edit]

while true
fprintf('SPAM\n')
end

Maxima[edit]

do(disp("SPAM"));

MAXScript[edit]

while true do print "SPAM\n"

Metafont[edit]

forever: message "SPAM"; endfor end

МК-61/52[edit]

1	2	3	4	С/П	БП	00

Note: because this device has no text output instead of "SPAM" was used the number (1234).

Modula-2[edit]

LOOP
InOut.WriteString ("SPAM");
InOut.WriteLn
END;

Modula-3[edit]

LOOP
IO.Put("SPAM\n");
END;

Monte[edit]

 
while (true):
traceln("SPAM")
 

MOO[edit]

while (1)
player:tell("SPAM");
endwhile

MUMPS[edit]

 
FOR WRITE "SPAM",!
 

Nemerle[edit]

while (true) WriteLine("SPAM");

Or, using recursion:

def loop() : void
{
WriteLine("SPAM");
loop();
}

NetRexx[edit]

/* NetRexx */
options replace format comments java crossref savelog symbols nobinary
 
say
say 'Loops/Infinite'
 
loop label spam forever
say 'SPAM'
end spam
 

NewLISP[edit]

(while (println "SPAM"))

Nim[edit]

while true:
echo "SPAM"

Oberon-2[edit]

 
MODULE InfiniteLoop;
IMPORT
Out;
BEGIN
LOOP
Out.String("SPAM");Out.Ln
END
END InfiniteLoop.
 

Objeck[edit]

 
while(true) {
"SPAM"->PrintLine();
};
 

OCaml[edit]

while true do
print_endline "SPAM"
done

or

let rec inf_loop() =    
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.

Occam[edit]

#USE "course.lib"
PROC main (CHAN BYTE screen!)
WHILE TRUE
out.string("SPAM*c*n", 0, screen)
:

Octave[edit]

while(1)
disp("SPAM")
endwhile

Oforth[edit]

begin "SPAM" . again

Oz[edit]

for do
{Show 'SPAM'}
end

PARI/GP[edit]

while(1,
print("SPAM")
);

For a shorter version, note that print returns gnil which is evaluated as false. A 'cheating' solution might use print(SPAM) on the hope that the variable SPAM is uninitialized and hence prints as the monomial in itself. But with the ' operator that evaluation can be forced, regardless of the current value (if any) of that variable:

until(print('SPAM),)

Pascal[edit]

while true do
writeln('SPAM');

Alternatively:

repeat
writeln('SPAM')
until false;

Perl[edit]

print "SPAM\n" while 1;

Perl 6[edit]

Works with: Rakudo Star version 2010.08
loop {
say 'SPAM';
}

In addition, there are various ways of writing lazy, infinite lists in Perl 6:

print "SPAM\n" xx *;      # repetition operator
print "SPAM\n", ~* ... *; # sequence operator
map {say "SPAM"}, ^Inf; # upto operator

Phix[edit]

while 1 do
puts(1,"SPAM\n")
end while

PHP[edit]

while(1)
echo "SPAM\n";

PicoLisp[edit]

(loop (prinl "SPAM"))

Pike[edit]

int main(){
while(1) write("SPAM\n");
}

PL/I[edit]

 
do forever;
put list ('SPAM'); put skip;
end;
 

Pop11[edit]

while true do
printf('SPAM', '%p\n');
endwhile;

PostScript[edit]

{}loop

PowerShell[edit]

for () {
"SPAM"
}

Prolog[edit]

repeat, write('SPAM'), nl, fail.

Pure Data[edit]

Screenshot: https://i.imgur.com/IrwaafZ.png

#N canvas 426 88 450 300 10;
#X obj 17 75 print;
#X msg 17 55 SPAM;
#X obj 17 35 metro 1;
#X msg 17 15 1;
#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.

PureBasic[edit]

Repeat/Forever[edit]

Repeat 
PrintN("SPAM")
ForEver

Goto[edit]

PrintIt:
PrintN("SPAM")
Goto PrintIt

Python[edit]

while 1:
print "SPAM"

Note: one can also use: "True" or any other non-false value. In Python the following values are false: 0, "" (empty string), (,) and {} and [] (empty tuples, dictionaries or lists), None (the special object), and the False object. Any non-empty collection or string or non-zero numeric value is considered "True". However, according to Python Wiki, for Python versions 2.3+ this variant is optimized by the interpreter and thus is the fastest.

R[edit]

Note that the default R Gui buffers outputs before pushing them to the screen. 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.

repeat print("SPAM")

Racket[edit]

 
#lang racket
 
;; Using recursion
(define (loop)
(displayln "SPAM")
(loop))
 
(loop)
 
;; Using a for loop
(for ([i (in-naturals)])
(displayln "SPAM"))
 

REBOL[edit]

forever [print "SPAM"]

Retro[edit]

[ "SPAM\n" puts -1 ] while

REXX[edit]

simple[edit]

/*REXX program displays the  word      SPAM      forever.               */
 
do forever
say 'SPAM'
end /*DO forever*/
/*control will never reach here. */
/*don't stick a fork in it. */

esoteric[edit]

/*REXX program displays the  word      SPAM      forever.               */
 
do while 1==1 /*esoteric "forever" clause. */
say 'SPAM'
end /*DO while 1==1*/
/*control will never reach here. */
/*don't stick a fork in it. */

GO TO version[edit]

/*REXX program displays the  word      SPAM      forever.               */
 
tell_it: say 'SPAM'
signal tell_it /*REXX's version of a GO TO */
 
/*control will never reach here. */
/*don't stick a fork in it. */

too clever by half[edit]

/*REXX program displays the  word      SPAM      forever.               */
 
do until 0>1 /*too-clever-by-half forever loop*/
say 'SPAM'
end /*DO until 0>1*/
/*control will never reach here. */
/*don't stick a fork in it. */

Ring[edit]

 
while true
see "Spam"
end
 

Ruby[edit]

loop {puts "SPAM"}
 

Rust[edit]

fn main() {
loop {
println!("SPAM");
}
}

Run BASIC[edit]

[loop] print "Spam" :goto [loop]
 
while 1
print "Spam"
wend


S-lang[edit]

forever print("SPAM");

Salmon[edit]

while (true)
"SPAM"!;

Sather[edit]

class MAIN is
main is
loop
#OUT + "Spam\n";
end;
end;
end;

Scala[edit]

while (true)
println("SPAM")

Scheme[edit]

((lambda (x) (display "SPAM") (newline) (x x))
(lambda (x) (display "SPAM") (newline) (x x)))
 

or, less Schemishly but with less redundancy:

(do () (#f) (display "SPAM") (newline))

Scilab[edit]

Works with: Scilab version 5.5.1
while %T
printf("SPAM\n")
end
Output:
SPAM
SPAM
SPAM
SPAM
...

sed[edit]

:loop
s/.*/SPAM/
p
t loop

Sed requires at least one line of input to execute, so run as follows:

echo | sed ':loop;s/.*/SPAM/;p;t loop'

Seed7[edit]

$ include "seed7_05.s7i";
 
const proc: main is func
begin
while TRUE do
writeln("SPAM");
end while;
end func;

Self[edit]

['SPAM' printLine] loop

Sidef[edit]

loop { say "SPAM!" };

Slate[edit]

[inform: 'SPAM'] loop

Smalltalk[edit]

[ true ] whileTrue: [ 'SPAM' displayNl ]

SNOBOL4[edit]

loop output = "SPAM" :(loop)
end

SNUSP[edit]

@\>@\>@\>@\>++++++++++===!/ < < < < \
| | | \M=@@@@+@+++++# \.>.>.>.>./
| | \A=@@+@@@@+++#
| \P=@@+@@+@@+++#
\S=@@+@+@@@+++#

Sparkling[edit]

while true {
print("SPAM");
}

or

do {
print("SPAM");
} while true;

or

for var b = true; b; b = true {
printf("SPAM\n");
}

etc.

Standard ML[edit]

while true do
print "SPAM\n";

or

let 
fun inf_loop () = (
print "SPAM\n";
inf_loop ()
)
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.

Swift[edit]

while true {
println("SPAM")
}

SystemVerilog[edit]

program main;
initial forever $display("SPAM");
endprogram
 

Transact-SQL[edit]

WHILE 1=1 BEGIN
PRINT "SPAM"
END

Tcl[edit]

while true {
puts SPAM
}
# or
for {} 1 {} {
puts SPAM
}

TI-83 BASIC[edit]

There are a few ways to achieve this in TI-83 BASIC

 
 :Lbl 1
 :Disp "SPAM
 :Goto 1
 

Another way is by using a While loop

 
 :While 1
 :Disp "SPAM
 :End
 

TI-89 BASIC[edit]

Loop
Disp "SPAM"
EndLoop

TorqueScript[edit]

While(1)
echo("SPAM");

Trith[edit]

["SPAM" print] loop

TUSCRIPT[edit]

TUSCRIPT has no infinite loop. 999999999 loops are the limit.

 
$$ MODE TUSCRIPT
LOOP/999999999
print "spam"
ENDLOOP
 

UNIX Shell[edit]

Works with: Bourne Shell

Use any of these loops:

while :; do echo SPAM; done
while true; do echo "SPAM"; done
until false; do echo "SPAM"; done
Works with: bash
Works with: ksh93
Works with: zsh
for ((;;)); do echo "SPAM"; done

C Shell[edit]

while (1)
echo SPAM
end

es[edit]

forever {echo SPAM}

UnixPipes[edit]

yes SPAM

Unlambda[edit]

 ``ci``s``s`kr``s``s``s``s`k.S`k.P`k.A`k.Mii

Ursa[edit]

Translation of: Python
while true
out "SPAM" endl console
end while

V[edit]

true [
'SPAM' puts
] while

Vala[edit]

for(;;) stdout.printf("SPAM\n");
while(true) stdout.printf("SPAM\n");
do stdout.printf("SPAM\n"); while(true);

Vedit macro language[edit]

while (1) {
Message("Spam\n")
}

or:

do {
Message("Spam\n")
} while (1)

or:

for (;1;) {
Message("Spam\n")
}

"Nearly infinite" loop can be done by using constant ALL (=1073741824) as repeat count:

Repeat (ALL) {
Message("Spam\n")
}

Visual Basic[edit]

Do
Debug.Print("SPAM")
Loop

Visual Basic .NET[edit]

Platform: .NET

Works with: Visual Basic .NET version 9.0+
Do
Console.WriteLine("SPAM")
Loop

Wart[edit]

repeat :forever
prn "spam"

X86 Assembly[edit]

Works with: NASM version Linux
 
section .text
global _start
 
_start:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80
jmp _start
 
section .data
msg db "SPAM",0xa
len equ $-msg
 

XPL0[edit]

code Text=12;
loop Text(0, "SPAM
")

Z80 Assembly[edit]

Using the Amstrad CPC firmware:

org		$4000
 
txt_output: equ $bb5a
 
start: ld hl,spam
 
print: ld a,(hl)
cp 0
jr z,start
call txt_output
inc hl
jr print
 
spam: defm "SPAM\r\n\0"

zkl[edit]

while(1)   { println("SPAM") }
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