14
\$\begingroup\$

Given an input, output that input followed by a newline endlessly.

Input will be a string consisting only of printable ASCII characters (0x20-0x7E) and newlines (0x0A).

If input is length 0, endlessly output newlines.

This is so fewest bytes in each language wins!

\$\endgroup\$
4
  • \$\begingroup\$ Half of yes is 91 lines long. \$\endgroup\$
    – manatwork
    Jun 5 '17 at 9:08
  • 5
    \$\begingroup\$ So related it hurts. \$\endgroup\$ Jun 5 '17 at 13:23
  • \$\begingroup\$ @VoteToClose I knew I've answered this before.. \$\endgroup\$
    – L3viathan
    Jun 6 '17 at 9:49
  • \$\begingroup\$ Microsoft, 1 Steve Ballmerdevelopers, developers, developers, developers, ... \$\endgroup\$
    – sergiol
    Jun 8 '17 at 0:43

49 Answers 49

1
2
1
\$\begingroup\$

SAS, 32 bytes

%macro t(s);%put&s;%t(&s);%mend;
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 17 bytes

This one taking a reasonable position towards the shorter end of the non-golf-langs:

$f={for(){$args}}

The infinite recursion approach works, at least for a while, but isn't as terse:

$f={($s="$args");& $f $s}
\$\endgroup\$
1
\$\begingroup\$

Husk, 1 byte

Try it online!

In Husk, builds an infinite list repeating its argument forever. If a full program produces a list of strings as result, they get printed by joining them with newlines. The wonderful thing about Husk's laziness is that computations involving infinite lists can be managed and used to produce useful output, like in this case :)

\$\endgroup\$
1
\$\begingroup\$

T-SQL, 45 bytes

CREATE PROC r @ TEXT=NULL AS G:PRINT @ GOTO G

Usage

EXECUTE r 'Hello word!'
\$\endgroup\$
1
\$\begingroup\$

Keg, -pn, 2 bytes

{⑩

Try it online!

Forever, print the top of the stack with a newline without popping it.

\$\endgroup\$
0
\$\begingroup\$

Actually, 6 bytes

1W@;.@

Try it online!

Explanation:

1W@;.@  (implicit input)
1       push 1
 W      loop while top of stack is truthy:
  @       move input to top of stack
   ;.     duplicate and print
     @    move 1 to top of stack to continue loop
\$\endgroup\$
0
\$\begingroup\$

QBIC, 3 bytes

{?;

Explanation

{      DO
 ?     PRINT
  ;    a string read from the cmd line
       DO is implicitly closed by EOF
\$\endgroup\$
2
  • \$\begingroup\$ What on earth is QBIC in Google Drive for??? \$\endgroup\$
    – MD XF
    Jun 5 '17 at 18:16
  • \$\begingroup\$ @MDXF 'cause I can't handle any other source control solution... \$\endgroup\$
    – steenbergh
    Jun 5 '17 at 19:55
0
\$\begingroup\$

Go, 46 bytes

import."fmt"
func f(s string){for{Println(s)}}

Try it online!

Recursive approach, 46 bytes

Surprisingly, a recursive approach led to the same byte count.

import."fmt"
func f(s string){Println(s);f(s)}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Avoid the import."fmt" by using the built-in print command: func f(s string){for{print(s+"\n")}} \$\endgroup\$
    – chowey
    Jun 5 '17 at 20:10
  • 1
    \$\begingroup\$ @chowey That prints to STDERR, not STDOUT. \$\endgroup\$ Jun 5 '17 at 20:11
0
\$\begingroup\$

tcl, 20

while 1 {puts $argv}

demo — on the green area type

tclsh main.tcl string you want to repeat

where string you want to repeat is the input for program.

DO NOT USE BACKSPACE KEY ON GREEN AREA! It will make browser go back in history.

\$\endgroup\$
0
\$\begingroup\$

shortC, 7 bytes

AWJ@[1]

Explanation:

A        main function
 W       while loop
  J      print string with newline
   @[1]  first command line argument

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Chip, 19+3 = 22 bytes

+3 for flag -z, which adds an infinite stream of 0x00 bytes to the end of the input.

cCGgbbBAa
fF^~^dDEe

Try it online!

The behavior, in pseudocode:

out_byte := in_byte
if !(in_byte & 0x60) {
    out_byte |= 0x0A
}

Basically, if both bits 0x20 and 0x40 are unset, then either we have a newline character, or we've hit the end of the input. In either case, we just output a newline character and carry on.

\$\endgroup\$
0
\$\begingroup\$

Aceto, 8 bytes

>v
np
rk

Uses sticky mode to avoid having to duplicate the string.

\$\endgroup\$
0
\$\begingroup\$

OIL, 12 bytes

5

4

11
6
2

Read a value into the 0th line, print the value in the 0th line, print a newline, then jump to line 2.

\$\endgroup\$
0
\$\begingroup\$

Reticular, 9 bytes

i1=v
1`p>

Try it online!

Explanation:

i1=        Sets variable 1's value to a single line of input read from STDIN
   v       Change direction to down
   >       Change direction to right, wrap from end of line
1`p        1` fetches the value of variable 1, p prints it
\$\endgroup\$
0
\$\begingroup\$

Python 3, 22 bytes

while 1:print(input())

Surprised not to have seen a python 3 answer yet.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Welcome to PPCG! This code won't work currently, as it will call input() each time, meaning it will only output the input once. I highly suggest using TIO for testing and formatting your answer, it makes life much easier \$\endgroup\$
    – Skidsdev
    Jun 6 '17 at 15:57
  • 1
    \$\begingroup\$ I think this is as short as one can get in python3, although I'm not great at python3 golfing, I usually golf in weird esoteric languages \$\endgroup\$
    – Skidsdev
    Jun 6 '17 at 16:00
  • \$\begingroup\$ @Mayube Ah, I misunderstood what was required. \$\endgroup\$
    – greenglass
    Jun 6 '17 at 16:30
0
\$\begingroup\$

Vim, 6 bytes

Similar solution as the V answer.

Yqqp@q
\$\endgroup\$
0
\$\begingroup\$

Python 3, 26 bytes

a=input()
while 1:print(a)

Try it online!

As simple as it gets.

\$\endgroup\$
0
\$\begingroup\$

W, 1 byte

It's not an infinitely-repeating built-in. That will be explained in the explanation.

I

Explanation

With implicit inputs this becomes:

aPI

  I % An infinite loop with the following body:
a   % Take a single input from the arguments
 P  % Implicitly print the inputted argument on every iteration
    % (The above printing only occurs if the operand expression)
    % hasn't been printed before
```
\$\endgroup\$
0
\$\begingroup\$

Hy, 34 bytes

(setv a(input))(while 1(print a))

Try it Online!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.