122
\$\begingroup\$

Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Specs

  • You may have extra trailing newlines.
  • You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

This is . Shortest answer in bytes wins.

\$\endgroup\$
10
  • 3
    \$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$
    – Leaky Nun
    Commented Aug 4, 2016 at 12:56
  • 16
    \$\begingroup\$ @DylanMeeus Since that is to do with the dev tools hiding repeated console outputs, and isn't native to JavaScript consoles as a whole and is not in the JavaScript spec - as well as the fact that feature can be turned off - i think it should be acceptable. Not all browsers will collapse it like that. \$\endgroup\$
    – James T
    Commented Aug 4, 2016 at 12:58
  • 9
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$
    – anna328p
    Commented Aug 4, 2016 at 22:08
  • 4
    \$\begingroup\$ One of the most interesting things about this challange is that depending on your language ********** can be shorter then a loop. Makes me wonder when it's better for a given language to switch between 1 or 2 loops. \$\endgroup\$
    – dwana
    Commented Aug 5, 2016 at 9:14
  • 3
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Commented Feb 10, 2017 at 2:34

413 Answers 413

1
\$\begingroup\$

Malbolge, 271 bytes

Generated here (linear generator). I tried other methods too but it took me pretty long time so I could not wait for completion.

D'`_:pon}}kXyxx5R-,s0Npn9+k#(EgDU0zyba+u)]xwvunV3210/.-,+*hg`H^c\"`_AW\UyxwvutsrqpJIHMLEDCg*@E>ba`_^]\[ZY9y765.-,+O/.nmJIHGFEDCBAya}|{ts9wvunV3210/.-,+*hg`H^c\"`_AW\UyxwvutsrqpJIHMLEDCg*@E>ba`_^]\[ZY9y765.-,+O/.nmJIHGFEDCBAya}|{ts9wvunV3210/.-,+*hg`H^c\"`_AW\Uyxwvutsrqp]

Try it online!

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

Arduino, 101 bytes

int i=0;void setup(){Serial.begin(300);}void loop(){if(i++<10)Serial.println("**********");else i--;}

The else case is there to prevent i from overflowing and becoming negative, since the loop() function is called indefinitely.

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

Python 3, 34 bytes

for i in range(10):
 print("*"*10)

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! I've edited your answer to make it a bit clearer and added a link to try it. There's a couple similar Python answers, but nice first answer! \$\endgroup\$ Commented Oct 1, 2021 at 16:09
  • \$\begingroup\$ You can save some bytes by inlining the for block, so it can be one line like for i in range(10):print("*"*10) \$\endgroup\$
    – hyper-neutrino
    Commented Oct 1, 2021 at 16:09
  • \$\begingroup\$ Also, make sure to check out our Tips for golfing in Python to see if there are any other ways to golf your code. \$\endgroup\$ Commented Oct 1, 2021 at 16:10
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 43 bytes

Outputs two trailing LFs.

 output =dupl(dupl('*',10) char(10),10)
end

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ I noticed replacing dupl('*',10) with '**********' results in number of bytes unchanged. \$\endgroup\$
    – user100411
    Commented Oct 30, 2021 at 0:52
1
\$\begingroup\$

jq, 16 bytes

10*("*"*10+"\n")

Try it online!

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

Aussie++, 71 bytes

G'DAY MATE!
I RECKON x IS A WALKABOUT FROM [0TO 9]<GIMME "**********";>

Tested in commit 0a5de7e, in which for loops do not behave as per the spec. The version presented here actually works in that commit.

\$\endgroup\$
4
  • \$\begingroup\$ Why is this noncompeting? \$\endgroup\$ Commented Oct 29, 2021 at 21:45
  • \$\begingroup\$ The language used was introduced years after the question was asked, and the question does not specify that newer languages are allowed. \$\endgroup\$
    – Bbrk24
    Commented Nov 1, 2021 at 0:35
  • \$\begingroup\$ That rule has been obsolete since 2017, and such answers no longer need to me marked. \$\endgroup\$ Commented Nov 1, 2021 at 4:10
  • \$\begingroup\$ Oh, I didn't know that. I'll remove the marking then. EDIT: It looks like you did for me. \$\endgroup\$
    – Bbrk24
    Commented Nov 1, 2021 at 4:41
1
\$\begingroup\$

KonamiCode, 103 bytes

v(^^^^>^^)>(^)v(^>)>(^^)v(>)>(^^^)v(>)S(^>)L(>)>(^^)v(>)L(^)>(>)<<>(^^)v((>))B(^)>(^)<<>(^^^)v((>))B(>)

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

Japt, 15 bytes

"*"p10)+"
")p10

Try it online!

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

Hodor, 240 bytes

hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");hodor.hod("**********");

Try it online!

I'm not good at Hodor

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

shortC, 33 bytes

AOIa=0;a<=10;a++)R"**********\n"}

Try it online!

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

tinylisp, 58 bytes

(d A(q((n *)(i n(i(disp *)0(A(s n 1)*))*
(A 9(q **********

Try it online!

We define a function A with two parameters: n is the number of iterations, and * is a row of asterisks (it will always be ten of them, but it saves bytes to pass that as an argument). If n is truthy (nonzero), we display the asterisk row (with trailing newline) and recurse with n minus 1. If n is falsey (zero), we simply return the asterisk row.

Calling the function with n = 9 results in 9 disp calls; the return value of the function is then displayed, giving us our 10th row.

\$\endgroup\$
3
  • \$\begingroup\$ remove 4 closing parens for 58? \$\endgroup\$
    – Razetime
    Commented Feb 4, 2022 at 3:16
  • \$\begingroup\$ Sure. They were needed when this answer was first written: back then, parens only autocompleted at the end of the program. \$\endgroup\$
    – DLosc
    Commented Feb 4, 2022 at 4:00
  • \$\begingroup\$ i see. interesting \$\endgroup\$
    – Razetime
    Commented Feb 4, 2022 at 4:01
1
\$\begingroup\$

Python 3, 23 bytes

Prints an extra newline at the end

print(f'{"*"*10}\n'*10)

Try it online!

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

Python 3, 23 bytes

print(("*"*10+"\n")*10)

Felt like entering a Python 3 program too.

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

Python 3, 23 bytes

print(('*'*10+'\n')*10)

Try it online!

(Note: new to codegolf and stackexchange in general, this is my first attempt at any code-golfing challenge)

Edit: this is a pretty generic answer, and pretty boring too, although valid and pretty short.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf! \$\endgroup\$ Commented Jul 9, 2022 at 19:14
  • \$\begingroup\$ @NoHaxJustRadvylf Thank you! \$\endgroup\$ Commented Jul 9, 2022 at 19:17
1
\$\begingroup\$

Kotlin, 34 bytes

println("**********\n".repeat(10))

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ You are right, i had missread the task :) \$\endgroup\$
    – wartoshika
    Commented Jul 10, 2022 at 7:34
1
\$\begingroup\$

Carrot, 10 9 bytes

*^*9^
^*9

Try it online! (copy & paste only)

*^                //pushes "*" to the stack
*9                //add 9 more copies of itself
                  //stack = "**********"
^\n^              //append a newline to it
*9                //add 9 more copies of the resulting string
                  //implicit output
\$\endgroup\$
2
  • \$\begingroup\$ Why is this non-competing? \$\endgroup\$ Commented Sep 24, 2020 at 1:18
  • \$\begingroup\$ @TheFifthMarshal Looking at the github repo it appears this program didn't work in the version of the language at the time of the challenge. I edited it anyway. \$\endgroup\$
    – emanresu A
    Commented Sep 4, 2022 at 6:48
1
\$\begingroup\$

Triangular , 28 bytes

A\(A@1].p-p..pA@...](/*76-1<

Try it online!

Expanded version:

       A 
      \ ( 
     A @ 1 
    ] . p - 
   p . . p A 
  @ . . . ] ( 
 / * 7 6 - 1 < 

Commands executed, excluding directional commands:

A(1-A(1-67*@p]A@pp]
\$\endgroup\$
1
  • \$\begingroup\$ How does this work? \$\endgroup\$ Commented Jun 17, 2017 at 15:01
1
\$\begingroup\$

Bits, 191 bits = 23.875 bytes

00000000000000000000000000000000000000000000000000000000000011100010110000011111011001111101100111110110011111011001111101100111110110011111011001111101100111110110011111011001110000011100011

Explained

  • The long string of 0s at the start is to make a string of length 10. (This is the only way to start a for loop in Bits)
  • 11100010 starts the for loop:
    • 1100000 is a separator so the strings don't join together
    • 1111101100 is the code for a *. We repeat this 10 times to get **********. (Note: this is the only way to repeat a string in Bits)
    • 11100000 prints the string
  • 11100011 closes the for loop

Screenshot

Screenshot

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

TacO, 25 bytes

0 01
1  *"*"
*###"\n"
w
@

Explaination

The program is a 2D program which can be broken up as so:

@       ; Program Entry
w       ; Write the result of everything STDOUT concatenated together
*10     ; Repeat 10 times
  *10   ; Repeat 10 times
    "*" ; Append "*"
  "\n"  ; Append a newline

Or the psudocode:

write(repeat(10,repeat(10,"*")+"\n")

Try it online!

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

Vyxal 3 j, 5 bytes

₅•×₀÷

Try it Online!

RIP -H flag and squarify strings which could make this 3 bytes

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

Acc!!, 48 bytes

Count i while i-110 {
Write 42-32*0^((i+1)%11)
}

Try it online!

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

+Output, 19 12 bytes

Note: +Output is an extension to -Output, both of which are languages I made.

"*"a*aU+a*oX

Explanation: This language revolves around a stack. Digits 0-f will push the number onto the stack. a (10) is used a few times to push 10.

"*"a*        | pushes * and multiples the string by 10 to get **********
     aU+     | push newline with aU and add the strings together to get **********\n
        a*oX | multiply **********\n whole thing by 10 and output it

Old answer (19 bytes)

a"*"a*oaUo1n+:!#X_#

Explanation:

a                   | Set loop counter (10)
 "*"a*o             | Push *, multiply it by 10 to get **********, and output it
       aUo          | Output newline
          1n+       | Decrement the loop counter
             :!#X_# | Check if loop counter is 0
\$\endgroup\$
0
\$\begingroup\$

C++, 76 bytes

I don't know if this could be golfed further, but just.

#include <iostream>
void a(){for(int i=0;i++<10;)std::cout<<"**********\n";}
\$\endgroup\$
4
  • \$\begingroup\$ No, I tried that. \$\endgroup\$
    – user54200
    Commented Aug 4, 2016 at 10:30
  • 5
    \$\begingroup\$ You can save a few bytes by using puts from cstdio instead of cout (save in header name, function name, plus line terminator for free). Also one byte by making i global (which gets zero initialized for free). \$\endgroup\$
    – Mat
    Commented Aug 4, 2016 at 12:23
  • 1
    \$\begingroup\$ This isn't a whole program (no main) so do you need the include? \$\endgroup\$ Commented Jul 2, 2018 at 0:07
  • \$\begingroup\$ tio.run/##S9ZNT07@/z/… Here is a version with Mat's suggestions \$\endgroup\$ Commented Oct 14, 2020 at 21:07
0
\$\begingroup\$

C# - 88 bytes

class P{static void Main(){int i=0;while(i++<10)System.Console.Write("**********\n");}}
\$\endgroup\$
2
  • \$\begingroup\$ You can reduce this a bit by using a for look, putting int i inside it for(int i=10;i-->0;) (There is never a reason to use a straight while loop in C# code golf, a for loop is never more expensive) \$\endgroup\$ Commented Aug 4, 2016 at 17:24
  • \$\begingroup\$ I know, but then I would have been copying and pasting an already existing answer. \$\endgroup\$
    – pay
    Commented Aug 4, 2016 at 17:28
0
\$\begingroup\$

Perl, 24 bytes

print((("*"x10).$/)x10);

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

Javascript (using external library - Enumerable) (41 bytes)

_.From("**********\n").Cycle(120).Write()

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: This runs right in the console. Load the string into the library, which parses it to a char array enumerable. Create a new enumerable from that sequence, which is generated by cycling from start to finish 120 times (because the string length is 12, and we want 10 of them..12*10=120). I.e [1,2,3].Cycle(10) would be 1,2,3,1,2,3,1,2,3,1. Finally, join everything into a string with "" as delimiter

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ OH, .length lied to me ahah...I thought it would count "\" and "n" as separate characters..fixed! \$\endgroup\$ Commented Aug 4, 2016 at 17:58
  • \$\begingroup\$ Next time use mothereff.in/byte-counter \$\endgroup\$ Commented Aug 5, 2016 at 0:01
  • \$\begingroup\$ @PatrickRoberts Got it, thanks! \$\endgroup\$ Commented Aug 5, 2016 at 0:07
0
\$\begingroup\$

Ruby, 18 bytes

puts (?**10+$/)*10

Alternative version (+3 bytes)

10.times {puts ?**10}

Ungolfed (first version)

puts ('*' * 10 + '\n') * 10
\$\endgroup\$
1
0
\$\begingroup\$

Swift 2, 45 Bytes

func a(){for _ in 0...9{print("**********")}}
\$\endgroup\$
0
\$\begingroup\$

Wolfram, 22 bytes

Grid[Table["*",10,10]]
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to PPCG! I can't test right now, but I don't think this is a full program (it only displays correctly when used in Mathematica's notebook front end, which constitutes a snippet by this community's standards). If you put this in a source file and call it with wolfram -script file.m I don't think it'll print anything. I think the shortest way to get around that would be Print@@@Table["*",10,10]. Still, nice solution! :) \$\endgroup\$ Commented Aug 4, 2016 at 20:11
  • \$\begingroup\$ You are correct. Also, your solution works and is 24 bytes long. \$\endgroup\$ Commented Aug 4, 2016 at 20:29
0
\$\begingroup\$

R

matrix(rep("*",100), nrow = 10)

Probably faster way in R, but fun utilization of matrix

Explanation

rep: repeats first argument as many times as second argument.

matrix: creates matrix from vector (first argument), and nrow is the number rows desired in matrix.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hi, and welcome to PPCG! However, we require all code to be golfed, which this isn't. Please golf it. \$\endgroup\$
    – Riker
    Commented Aug 5, 2016 at 0:07
  • 1
    \$\begingroup\$ To make it print the actual desired output you would need to loop cat over it, one way or another. In addition, because of vector recycling, matrix("*",nr=10,nc=10) or array("*",c(10,10)) would be more concise to get the same matrix as the one you generate. \$\endgroup\$
    – plannapus
    Commented Aug 5, 2016 at 7:12
  • \$\begingroup\$ You are right in all regards. This works :for(i in 1:10){for (j in 1:10){cat("*");if(j == 10){cat("\n")}}} \$\endgroup\$
    – cgage1
    Commented Aug 5, 2016 at 16:54

Your Answer

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

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