Loops/Infinite

From Rosetta Code
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.


Related tasks



11l[edit]

L
   print(‘SPAM’)

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

68000 Assembly[edit]

Hardware-specific routines for I/O are left unimplemented and just displayed as a subroutine, as this is not the focus of the task.

doSPAM:
LEA Message,A0
JSR PrintString
JMP doSPAM

Message:
DC.B "SPAM",13,10,0
EVEN

8086 Assembly[edit]

Works with: [DOSBox]

Loading Immediates[edit]

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

Loading From A Data Source[edit]

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

8th[edit]

One way:

: inf "SPAM\n" . recurse ;

Another way:

: inf repeat "SPAM\n" . again ;

AArch64 Assembly[edit]

Works with: as version Raspberry Pi 3B version Buster 64 bits
/* 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"

ACL2[edit]

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

Action![edit]

PROC Main()
  DO
    PrintE("SPAM")
  OD
RETURN
Output:

Screenshot from Atari 8-bit computer

SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
SPAM
...

ActionScript[edit]

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

Ada[edit]

loop
   Put_Line("SPAM");
end loop;

Agena[edit]

Tested with Agena 2.9.5 Win32

do
    print( "SPAM" )
od

Aime[edit]

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

ALGOL 60[edit]

Translation of: ALGOL W


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 version OS/360
'BEGIN' 'COMMENT' Loops/Infinite - Algol60 - 23/06/2018;
  'INTEGER' I;
  'FOR' I := 1 'STEP' 0 'UNTIL' 2 'DO' 
    OUTSTRING(1,'('SPAM')')
'END'

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"

ArnoldC[edit]

IT'S SHOWTIME
STICK AROUND @NO PROBLEMO
TALK TO THE HAND "SPAM"
CHILL
YOU HAVE BEEN TERMINATED

Arturo[edit]

while [true] [
	print "SPAM"
]

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: Commodore BASIC
Works with: ZX Spectrum Basic

The most intuitive method is to use the GOTO statement.

10 print "SPAM"
20 goto 10

Generally, using GOSUB in place of GOTO is incorrect. Some programming bugs come about when a GOSUB causes a potentially infinite loop, however, eventually stack memory will fill up and cause a terminating error as shown in this Commodore BASIC example:

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.
█

The solution is to keep the stack empty, however, this will also clear all variables used and prevent the use of RETURNing from the "subroutine". This is accomplished with the CLEAR (or CLR in Commodore BASIC) placed at the start of the loop.

10 clr:print "Commodore Spam! ";:gosub 10
10 clear : print "Apple Spam! ";: gosub 10

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

10 for i = 1 to 10 step 0 : rem A zero step makes the loop infinite
20 print "SPAM";
30 next i

In most cases, we can also call the RUN command from within the program.

10 print "Spam! ";
20 run

IF... THEN has an implied GOTO on some BASICs...

10 print "SPAM SPAM! ";:if 1 then 10

Applesoft BASIC[edit]

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


BASIC256[edit]

while true
    print "SPAM"
end while

Commodore BASIC[edit]

In addition to the general examples listed above for 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 GOTO or GOSUB 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, POKE 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 LIST routine follows the linked list pointers) can be manipulated in the same manner if it is known where BASIC program memory starts.

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.
█

IS-BASIC[edit]

100 DO
110   PRINT "SPAM"
120 LOOP

QB64[edit]

'Using Do loop
Do                'Alternatively this could have a conditional, "Do While 1"
     Print "SPAM"
Loop

'Using While loop
While 1
     Print "SPAM"
Wend


True BASIC[edit]

DO
   PRINT "SPAM"
LOOP
END

Yabasic[edit]

do
  print "SPAM"
loop

O también

while true
  print "SPAM"
wend

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
"

BCPL[edit]

get "libhdr"

let start() be writes("SPAM*N") repeat

beeswax[edit]

_>`SPA`p
  bN`M`<

Befunge[edit]

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

55+"MAPS",,,,,

blz[edit]

while true
    print("SPAM")
end

bootBASIC[edit]

Using goto:

10 print "SPAM"
20 goto 10

Using run:

10 print "SPAM"
20 run

BQN[edit]

The main way of performing an infinite loop in BQN is using recursion.

{𝕊 •Out 𝕩}"SPAM"

will likely end in a stack overflow.

Bracmat[edit]

whl'out$SPAM

Brainf***[edit]

Optimized for code size:

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

Optimized for execution speed:

10++++++++++
[-> 8++++++++ > 8++++++++ > 6++++++ > 8++++++++ > 1+ <<<<<]>
83+++ > 80 > 65+++++ > 77--- <<<
[.>.>.>.>.<<<<]

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"));

or

spam: puts("SPAM");
goto spam;

C#[edit]

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

C++[edit]

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

or

for (;;)
  std::cout << "SPAM\n";

or

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

Chapel[edit]

while true do writeln("SPAM");

ChucK[edit]

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

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'

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>

Comal[edit]

LOOP
   PRINT "SPAM"
ENDLOOP

Common Lisp[edit]

(loop (write-line "SPAM"))

Using DO[edit]

(do ()					; Not initialization
    (nil)				; Not break condition
  (print "SPAM"))			; On every loop as requested
Output:
"SPAM"
...

Corescript[edit]

:top
print Spam!
goto top

Cowgol[edit]

include "cowgol.coh";

loop
    print("Spam\n");
end loop;

Crystal[edit]

loop do
    puts "SPAM"
end

Using while/until:

while true
    puts "SPAM"
end
until false
    puts "SPAM"
end

Using an infinite range:

(0..).each do
    puts "SPAM"
end

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;
}

Dart[edit]

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

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

Delphi[edit]

See Pascal

Draco[edit]

proc nonrec main() void:
    while true do
        writeln("SPAM")
    od
corp

DWScript[edit]

while True do
   PrintLn('SPAM');

Dyalect[edit]

while true {
    print("SPAM")
}

Déjà Vu[edit]

while true:
	!print "SPAM"

Infinite recursion thanks to tail calls:

labda:
	!print "SPAM"
	recurse
call

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.

EDSAC order code[edit]

The EDSAC instruction set does not include an unconditional jump: it is necessary to synthesize it by using either an E "branch on accumulator sign bit clear" or F "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 T "transfer and clear" order to store the accumulator's contents in storage address θ+17, then jump back to the beginning of the loop and reload the accumulator with an A "add" order. Note that the storage address used as a temporary variable should be set to zero on entry to the loop.

[ Infinite loop
  =============

  A program for the EDSAC

  Works with Initial Orders 2 ]

        T56K
        GK

        O10@  [ letter shift ]

[  1 ]  A17@  [ a += C(17@) ]
        O11@
        O12@
        O13@
        O14@
        O15@
        O16@
        T17@  [ C(17@) = a; a = 0 ]
        E1@   [ if a >= 0 goto 1@ ]

[ 10 ]  *F
[ 11 ]  SF
[ 12 ]  PF
[ 13 ]  AF
[ 14 ]  MF
[ 15 ]  @F    [ carriage return ]
[ 16 ]  &F    [ line feed ]

[ 17 ]  PF

        EZPF

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]

ELENA 4.x:

public program()
{
    while (true)
    {
        console.writeLine:"spam"
    }
}

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)

Emacs Lisp[edit]

(while t
  (message "SPAM"))

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]

Tail recursion:

: spam ( -- ) "SPAM" print spam ;

Looping combinators:

[ "SPAM" print t ] loop
USE: combinators.extras
[ "SPAM" print ] forever

FALSE[edit]

[1]["SPAM
"]#

Fantom[edit]

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

Fermat[edit]

while 1 do !!'SPAM'; od

Fish[edit]

a"MAPS"ooooo

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

Fortress[edit]

component loops_infinite
  export Executable
  run() = while true do
    println("SPAM")
  end
end

FreeBASIC[edit]

' FB 1.05.0

Do
  Print "SPAM"
Loop

Frink[edit]

while true
   println["SPAM"]

FutureBasic[edit]

Loop de loop -- whose great idea was this?

include "NSLog.incl"

dispatchglobal
  while 1
    NSLog(@"SPAM")
  wend
dispatchend

HandleEvents

Gambas[edit]

Click this link to run this code

Public Sub Main()

Do
  Print "SPAM"
Loop

End

GAP[edit]

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

GB BASIC[edit]

10 print "SPAM"
20 goto10

GlovePIE[edit]

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.

debug = "SPAM"

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'
}

Halon[edit]

forever {
    echo "SPAM";
}

or (due to optimizations, these are equally fast)

while (true) {
    echo "SPAM";
}

Hare[edit]

use fmt;

export fn main() void = {
	for (true) {
		fmt::println("SPAM")!;
	};
};

Haskell[edit]

forever (putStrLn "SPAM")

or

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

Haxe[edit]

while (true)
  Sys.println("SPAM");

hexiscript[edit]

while true; println "SPAM"; endwhile

HicEst[edit]

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

HolyC[edit]

while(1) Print("SPAM\n");

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.

Jsish[edit]

for (;;) puts('SPAM');

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"]

Kotlin[edit]

// version 1.0.6

fun main(args: Array<String>) {
    while (true) println("SPAM")
}

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

Lambdatalk[edit]

{def loops_infinite
 {lambda {}
  {if true then SPAM{br} {loops_infinite} else never}}}
-> loops_infinite

{loops_infinite}
-> SPAM forever...

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")

Lingo[edit]

repeat while TRUE
  put "SPAM"
end repeat

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

M2000 Interpreter[edit]

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.

Module CheckIt {
      Print "SPAM"
      loop
}
Checkit

Using a Repeat (or Do) - Always block

Module CheckIt {
      Repeat {
            Print "SPAM"
      } Always
}
Checkit

Printing text rendering using Report.

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
            }

M4[edit]

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

Make[edit]

spam:
   @echo SPAM
   $(MAKE)


Malbolge[edit]

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

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"

MelonBasic[edit]

Using Goto:1:

Say:"SPAM"
Goto:1

Using Goto:start:

Say:"SPAM"
Goto:start

Metafont[edit]

forever: message "SPAM"; endfor end

Microsoft Small Basic[edit]

With While.

While "True" 
  TextWindow.WriteLine("SPAM")
EndWhile

With Goto.

loopStart:
TextWindow.WriteLine("SPAM")
Goto loopStart

min[edit]

Works with: min version 0.19.3
(true) ("SPAM" puts!) while

MIPS Assembly[edit]

Thanks to Chibialiens.com for the header/footer, bitmap font, and print routines.

.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"
Output:

Screenshot of Nintendo 64 emulator

МК-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")

MontiLang[edit]

WHILE TRUE
    |SPAM| PRINT .
ENDWHILE

Note that TRUE is simply a variable equal to 1. WHILE 1, any number larger than 0 or any string with a length more than 0 would also work

MOO[edit]

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

MUMPS[edit]

 FOR  WRITE "SPAM",!

Nanoquery[edit]

while true
    println "SPAM"
end

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"

NS-HUBASIC[edit]

Using FOR:

10 FOR I=0 TO 1 STEP 0
20 PRINT "SPAM"
30 NEXT

Using GOTO:

10 PRINT "SPAM"
20 GOTO 10

Using RUN:

10 PRINT "SPAM"
20 RUN

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

Ol[edit]

(let loop ()
   (display "SPAM")
   (loop))

OPL[edit]

PROC main:
  LOCAL loop%
  loop%=1
  while loop%=1
  PRINT "SPAM"
  ENDWH
ENDP

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]

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

or equivalently

print "SPAM\n" while 1;

Phix[edit]

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

PHP[edit]

while(1)
    echo "SPAM\n";

PicoLisp[edit]

(loop (prinl "SPAM"))

Pike[edit]

while(1)
    write("SPAM\n");

PILOT[edit]

*TypeSpam
type:SPAM
jump:*TypeSpam

Pixilang[edit]

start:
fputs("SPAM\n")
go start

PL/I[edit]

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

Plain English[edit]

When Repeat. 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.

To run:
Start up.
Write SPAM forever.
Shut down.

To write SPAM forever:
Write "SPAM" to the console.
Repeat.

Plain TeX[edit]

Compile in console mode, with, e.g. "pdftex <file name>".

\newlinechar`\^^J
\def\spam{\message{SPAM^^J}\spam}%
\spam

Pop11[edit]

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

PostScript[edit]

simple infinite loop:

{}loop

A bit more complex infinite loop:

/go {
  /spam 
     { (SPAM\n) print flush } 
  bind def % bind and define spam

  { spam } % procedure that will be executed by loop and will call spam to print
  loop % the loop
}

%start spamming!
go

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]

In Python 2:

while 1:
   print "SPAM"

In python 3:

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.

Quackery[edit]

[ say "SPAM" cr again ]

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"))

Raku[edit]

(formerly Perl 6)

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

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

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

Rapira[edit]

while 1 do
  output: "SPAM"
od

REBOL[edit]

forever [print "SPAM"]

Red[edit]

forever [
print "SPAM"
]

ReScript[edit]

while true {
  Js.log("SPAM")
}

or

let rec inf_loop = () => {
  Js.log("SPAM")
  inf_loop()
}

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

Robotic[edit]

This will display the word SPAM at the bottom of the screen indefinitely:

: "infinite_loop"
* "SPAM"
goto "infinite_loop"

Ruby[edit]

loop {puts "SPAM"}

Run BASIC[edit]

[loop] print "Spam" :goto [loop]

while 1
print "Spam"
wend

Rust[edit]

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

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]

[
    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]

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.

Spin[edit]

Works with: BST/BSTC
Works with: FastSpin/FlexSpin
Works with: HomeSpun
Works with: OpenSpin
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)

SPL[edit]

>
  #.output("SPAM")
<

SQL PL[edit]

Works with: Db2 LUW
version 9.7 or higher.

With 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 @

Output:

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
...

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.

Stata[edit]

while 1 {
        display "SPAM"
}

Mata[edit]

while (1) printf("SPAM\n")

Also possible with a for loop, but unlike C, the middle expression is not optional:

for (;1;) printf("SPAM\n")

Swift[edit]

while true {
    println("SPAM")
}

SystemVerilog[edit]

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

Tailspin[edit]

1 -> \(
  <> 'SPAM$#10;' -> !OUT::write
     1 -> #
\) -> !VOID

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");

Transact-SQL[edit]

WHILE 1=1 BEGIN
 PRINT "SPAM"
END

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);

VAX Assembly[edit]

                               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

VBA[edit]

Do
   Debug.Print "SPAM"
Loop

VBScript[edit]

Do
    WScript.Echo("SPAM")
Loop

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

Vlang[edit]

fn main() {
	for {
		print("SPAM\n")
	}
}

Wart[edit]

repeat :forever
  prn "spam"

Wee Basic[edit]

let loop=1
while loop=1
print 1 "SPAM"
wend
end


Whenever[edit]

1 print("SPAM");
1;


Wren[edit]

while (true) System.print("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

XLISP[edit]

It is of course possible to use a WHILE loop with a condition that will always evaluate to true:

(defun keep-printing-spam ()
    (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 goto for; or rather, in XLISP we do not have goto (in so many words) but we can achieve the effect of it using tail recursion.

(defun keep-printing-spam ()
    (display "SPAM")
    (newline)
    (keep-printing-spam) )

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"

Zig[edit]

const std = @import("std");
pub fn main() !void {
    const stdout_wr = std.io.getStdOut().writer();
    while (true) try stdout_wr.writeAll("SPAM\n");
}

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

Zoomscript[edit]

For typing:

var loop
loop = 1
while ne loop 0
	print "SPAM"
	println
endwhile

For importing:

¶0¶var loop¶0¶loop = 1¶0¶while ne loop 0¶1¶print "SPAM"¶1¶println¶0¶endwhile