15
\$\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, 2017 at 9:08
  • 5
    \$\begingroup\$ So related it hurts. \$\endgroup\$ Jun 5, 2017 at 13:23
  • \$\begingroup\$ @VoteToClose I knew I've answered this before.. \$\endgroup\$
    – L3viathan
    Jun 6, 2017 at 9:49
  • \$\begingroup\$ Microsoft, 1 Steve Ballmerdevelopers, developers, developers, developers, ... \$\endgroup\$
    – sergiol
    Jun 8, 2017 at 0:43

49 Answers 49

12
\$\begingroup\$

Bash, 8 bytes

yes "$1"

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ damn, 10 minutes late! but this does not print out newlines as newlines. \$\endgroup\$
    – phil294
    Jun 5, 2017 at 9:29
  • \$\begingroup\$ sorry, I didn't mean the yes-newlines but any newlines that could be contained IN the input are instead printed out as \n. kind of depends on how you read the question :D \$\endgroup\$
    – phil294
    Jun 5, 2017 at 9:51
  • \$\begingroup\$ @Blauhirn Oh I misunderstood this part :/. You need to call this as ./script $'Hello\n World' to include real newlines. On TIO you can just add a newline to the command line argument \$\endgroup\$
    – ovs
    Jun 5, 2017 at 10:05
  • 1
    \$\begingroup\$ Are the quotations necessary? yes $1 works fine for me \$\endgroup\$
    – DrnglVrgs
    Jun 5, 2017 at 13:43
  • 2
    \$\begingroup\$ @DrnglVrgs this does not work for me for an empty input \$\endgroup\$
    – ovs
    Jun 5, 2017 at 13:49
10
\$\begingroup\$

05AB1E, 2 bytes

[,

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Why aren't you doing [I,? \$\endgroup\$
    – FrodCube
    Jun 5, 2017 at 11:23
  • \$\begingroup\$ @FrodCube: Because unfortunately that doesn't work with empty input :( \$\endgroup\$
    – Emigna
    Jun 5, 2017 at 11:49
  • \$\begingroup\$ @FrodCube: Actually, the question states input of length 0 and not empty input so I can decrease this :) \$\endgroup\$
    – Emigna
    Jun 5, 2017 at 11:51
  • 1
    \$\begingroup\$ @FrodCube: Yeah, it's a pretty new feature in 05AB1E actually. I'm sure Ohm will get it eventually as well. \$\endgroup\$
    – Emigna
    Jun 5, 2017 at 12:12
  • 11
    \$\begingroup\$ [= also works and is a smiley face; the smile is the only benefit lol. \$\endgroup\$ Jun 5, 2017 at 14:45
7
\$\begingroup\$

AutoHotkey, 20 Bytes

OP did not specify how the output should happen, said only it has to happen endlessly with a newline after it. AHK was not tailored for cmd interaction. So the output happens repeatedly in a ToolTip at mouse position:

tooltip

loop
tooltip,%1%`n`n

I like AHK's loop feature. loop repeats the next block forever, loop, 10 would repeat it 10 times. Sometimes I miss this feature in other languages like Python.

The escape character in AutoHotkey is ` (so there are no problems with backslashes in Windows paths). For some reason, a trailing newline is ignored so it is needed twice. (trayTip might not have this "bug" but I cannot test it because running with wine)

old answer:

loop
msgbox,%1%

I just realized that OP probably wont like this solution, the output happens with user-interaction and includes no newlines. I'll look for another way.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Well, you've got my upvote for a creative solution \$\endgroup\$
    – Mayube
    Jun 6, 2017 at 15:03
6
\$\begingroup\$

JavaScript (ES6), 24 bytes

f=a=>f(a,console.log(a))

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Ohm, 3 bytes

∞┼,

Try it online!

It doesn't work with an empty input because Ohm is bad at input handling compared to other languages, but you can input "".

Explanation

∞     Infinite loop next code (until ";" or end of line)
 ┼    Get first input
  ,   Println
\$\endgroup\$
6
  • \$\begingroup\$ This looks cool... Could you explain it :D \$\endgroup\$
    – Beta Decay
    Jun 5, 2017 at 10:46
  • \$\begingroup\$ @BetaDecay done! \$\endgroup\$
    – FrodCube
    Jun 5, 2017 at 11:16
  • 1
    \$\begingroup\$ FYI, Ohm v2 (hopefully coming soon-ish) will have much better input handling than before! \$\endgroup\$ Jun 5, 2017 at 14:23
  • \$\begingroup\$ @NickClifford cool! I'm looking forward to that! I like your language \$\endgroup\$
    – FrodCube
    Jun 5, 2017 at 14:26
  • 1
    \$\begingroup\$ Oooo... Is Ohm like 05AB1E with different commands?! Fervently starts reading GitHub pages \$\endgroup\$ Jun 5, 2017 at 14:54
5
\$\begingroup\$

sed, 5

:      # label (unnamed) 
p      # print the pattern space
b      # branch back to the label

Unnamed labels is an undocumented "feature" in sed that works with version 4.2.2, but may not work in future versions.

\$\endgroup\$
4
\$\begingroup\$

Jelly, 2 bytes

Ṅß

Try it online!

Print with a newline, repeat the whole link (program).

\$\endgroup\$
4
\$\begingroup\$

brainfuck, 27 bytes

+[>,]++++++++++[[<]>>[.>]<]

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Could you save a byte with ,[>,]++++++++++[[<]>[.>]<]? \$\endgroup\$ Jun 5, 2017 at 10:40
4
\$\begingroup\$

Python 2, 21 bytes

def f(s):print s;f(s)

Assumes no recursion limit

Try it online!

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

V, 2 bytes

òÙ

You can't try this online for obvious reasons.

ò    'Recursively
 Ù   'Duplicate the current line downwards
\$\endgroup\$
3
  • \$\begingroup\$ TIO actually runs for 60 seconds then terminates and prints the STDOUT up until the termination point truncated to the first 128KiB. \$\endgroup\$ Jun 5, 2017 at 14:47
  • 1
    \$\begingroup\$ In V because the output it inside of an nvim session, and isn't printed to STDOUT until it finishes, TIO kills the session and sees nothing on STDOUT. I didn't know about what you said, but unfortunately it doesn't fix V \$\endgroup\$
    – nmjcman101
    Jun 5, 2017 at 14:51
  • 1
    \$\begingroup\$ Ahhhh... That's unfortunate, I forgot the properties of V, I've only used it once unsuccessfully. \$\endgroup\$ Jun 5, 2017 at 14:53
4
\$\begingroup\$

LibreLogo, 33 bytes

Code:

x=input " repeat [ label x bk 9 ]

Explanation:

x = input "               ; Input Stored in x as String
repeat [                  ; Endless Loop
    label x               ; Print x in Current Position
    bk 9                  ; Move Back 9 pt
]

Result:

enter image description here

\$\endgroup\$
3
\$\begingroup\$

Ruby, 18 17 12 + 2 = 14 bytes

Run with the -n flag.

loop{$><<$_}

Edit: Thanks for @sethrin for the -n flag!

\$\endgroup\$
2
  • \$\begingroup\$ Use the -n flag and skip the gets. \$\endgroup\$
    – Kaia Leahy
    Jun 5, 2017 at 22:53
  • \$\begingroup\$ @sethrin Nice one! I did not know about this flag! \$\endgroup\$ Jun 6, 2017 at 8:18
3
\$\begingroup\$

Cubix, 6 bytes

AN/qvo

Test it here

  A
N / q v
  o
  • N/A Push Newline(10) and input onto the stack
  • v redirect into the loop
  • o/q loop that outputs a character and pushes it to the bottom of the stack continuously

I was going to remove the EOI (-1) indicator from the stack, but it doesn't appear to affect the output any, so have left it saving bytes.

\$\endgroup\$
2
\$\begingroup\$

Python 2, 25 bytes

s=input()
while 1:print s

Try it online!

Input is expected to be a Python literal (quotes for a string, square bracket or parentheses with comma-separated items for a list/tuple, etc.)

Python 3 would be +1 byte because print is a function, but also could do raw input without the 4-byte penalty for raw_input() in Python 2.

\$\endgroup\$
2
\$\begingroup\$

Brachylog, 3 bytes

ẉ?↰

Try it online!

Port of my Jelly answer.

\$\endgroup\$
2
\$\begingroup\$

PHP, 20 bytes

for(;;)echo"$argn
";
\$\endgroup\$
2
\$\begingroup\$

Haskell, 14 bytes

cycle.(++"\n")

Try it online!

Append a newline to the input and make list of infinite copies of it.

Alternative version, also 14 bytes:

unlines.repeat
\$\endgroup\$
1
  • \$\begingroup\$ The alternative version is quite elegant :) \$\endgroup\$ Jun 6, 2017 at 20:05
2
\$\begingroup\$

Braingolf, 14 12 bytes

#
V[R!&@v1+]

Try it online!

-2 bytes thanks to totallyhuman

Explanation

#\nV[R!&@v1+]  Implicit input of string as charcodes
#\n            Push charcode of newline
   V           Create stack2
    [R...v1+]  While loop, runs endlessly
      !&@      Print entire stack1 as chars without popping
\$\endgroup\$
0
2
\$\begingroup\$

C, 24 bytes

f(char*s){puts(s),f(s);}

Basically a recursive function that outputs the string before calling herself again. Its my second post on codegolf so please be nice :p

\$\endgroup\$
2
\$\begingroup\$

Haskell, 21 bytes

putStr.cycle.(++"\n")
\$\endgroup\$
1
\$\begingroup\$

Japt, 5 bytes

OpU;ß

Try it online!

Explanation

OpU;     output the input with a newline
    ß    run the code again with the same input
\$\endgroup\$
1
\$\begingroup\$

C#, 40 bytes

s=>{for(;;)System.Console.WriteLine(s);}
\$\endgroup\$
1
\$\begingroup\$

MATL, 4 bytes

`GDT

Try it Online

Explanation

`     % Do...while loop
  G   % Grab input
  D   % Display it on a new line
  T   % Literal TRUE to create an infinite loop
\$\endgroup\$
1
\$\begingroup\$

C, 26 bytes

f(char*s){for(;;)puts(s);}

A function, f, that takes a C-style string as a parameter, s. The body of the function loops repeatedly, passing the string to the library function puts, which outputs the string to the standard output (stdout) along with a trailing new-line.

Pretty simple stuff. The only hack here is taking advantage of default-int for the return value and then not actually returning a value. That doesn't matter in this case, though, since the function never returns (it just keeps printing forever)!

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ f(char*s){puts(s);f(s);} saves a few \$\endgroup\$
    – nmjcman101
    Jun 5, 2017 at 14:40
1
\$\begingroup\$

Groovy, 20 bytes

x={println it;x(it)}
\$\endgroup\$
1
  • \$\begingroup\$ Does this run forever since it is recursive? \$\endgroup\$
    – Twometer
    Jul 2, 2017 at 19:29
1
\$\begingroup\$

Java 8, 34 bytes

s->{for(;;System.out.println(s));}

Surprised there wasn't a Java answer yet.

Try it here. (Wait 60 second for it to time-out.)

\$\endgroup\$
4
  • \$\begingroup\$ you don't need to wait for it to timeout, it'll reach the max output buffer of 128kb much faster than that :P \$\endgroup\$
    – Mayube
    Jun 6, 2017 at 8:51
  • \$\begingroup\$ @Mayube Perhaps, but it's still running Real time: 60.008 s according to the Debug-section before it outputs the result (and gives two warnings 60-sec limit exceeded and 128kb exceeded). \$\endgroup\$ Jun 6, 2017 at 9:25
  • 1
    \$\begingroup\$ TIO also caches the results, so once it's been run and hit the timelimit, the output is cached and will simply be served to others who run it without actually re-compiling and running the code \$\endgroup\$
    – Mayube
    Jun 6, 2017 at 9:27
  • \$\begingroup\$ @Mayube True. I didn't knew this also applied to others. Thought it was a local cache. In that case you can ignore the "(Wait 60 second for it to time-out.)" in my answer. :) But if you check on the "disable output cache" setting you'll see it takes ~ 60 seconds. \$\endgroup\$ Jun 6, 2017 at 9:30
1
\$\begingroup\$

Pyth, 2 bytes

#

Unfortunately I can't remove Q :(

You need to run from command-line like this, so that this is competing:

python3 pyth.py -c "#
"

The interpreter has been fixed too.

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

><>, 16 bytes

i:0(?v
:o71.>~a{

Try it online!

As mentioned in the comments below my first attempt may have misunderstood the question so the newer 16 byte solution has been made, I have left the original below so people may see.

><>, 13 bytes

<ov!?+1:i
oa<

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ I think there's been a bracketing problem: this code returns "that input followed by (a newline endlessly)", while most of the other answers give "(that input followed by a newline) endlessly"… \$\endgroup\$
    – Not a tree
    Jun 6, 2017 at 9:52
  • \$\begingroup\$ @Notatree, Thanks for mentioning this, I have updated my answer to respect your comment :) \$\endgroup\$ Jun 6, 2017 at 10:28
  • \$\begingroup\$ Nice, my best try was 17 bytes! \$\endgroup\$
    – Not a tree
    Jun 6, 2017 at 10:35
  • \$\begingroup\$ @Notatree, I changed the check in the first line from 1+?!v to 0)?v which saved a byte, what was your solution, would be nice to see more ><> answers :) - I also believe with some nifty mirrors you may be able to remove the jump instructions too but haven't figured it out yet. \$\endgroup\$ Jun 6, 2017 at 10:39
  • 1
    \$\begingroup\$ @Notatree, you were really close to the 16 bytes as well, change your second line to a\~ then move your last line around 1 to o>{: and you would have made it. the jump is just to cut out on extra mirrors across lines but yours works just as well :) \$\endgroup\$ Jun 6, 2017 at 11:12
1
\$\begingroup\$

CJam, 6 bytes

q{_n}h

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ @LuisMendo Ooh didn't read that part... \$\endgroup\$ Jun 6, 2017 at 11:07
1
\$\begingroup\$

Perl 5, 27 bytes

while(1){print"$ARGV[0]\n"}

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ input will always be given, it just might be an empty string, so you should be able to do while(1){print"$ARGV[0]\n"} \$\endgroup\$
    – Mayube
    Jun 6, 2017 at 15:30
  • \$\begingroup\$ @Mayube - thx, updated answer. \$\endgroup\$
    – tale852150
    Jun 6, 2017 at 15:35
  • \$\begingroup\$ Also welcome to ppcg! I fixed the formatting on your answer for you, in the future I totally recommend using Try it online (linked in the edited answer) as it not only makes testing way easier, but can give you a fully formatted ppcg answer to post \$\endgroup\$
    – Mayube
    Jun 6, 2017 at 15:38
  • \$\begingroup\$ @Mayube - thx, glad to be here... \$\endgroup\$
    – tale852150
    Jun 6, 2017 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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