123
\$\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

419 Answers 419

1
\$\begingroup\$

Elixir, 35 bytes

for _<-0..9,do: IO.puts"**********"

Try it online!

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

VBScript, 39 bytes

For i=0 to 9
WSH.Echo "**********"
next

VBScript, 53 bytes

For i=0 to 9
WSH.Echo replace(space(10)," ","*")
next

The second solution is slightly more interesting......

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

ConTeXt (40 bytes)

Compile it here (note that the magic comment is only here for texlive.net and it's not needed in an offline compilation).

\let~\dorecurse\starttext~{10}{~{10}*\\}
\$\endgroup\$
1
\$\begingroup\$

Twue, 31 bytes

a::~**********\n
::=
aaaaaaaaaa

Try it on the website!

Simply defines the replacement a which maps to printing 10 asterisks. The main body consists of 10 as. Trying a secondary replacement b::=aa or b::=aaaaa both yield 33 bytes, which is unfortunately longer.

Whereas in some Thue interpreters, outputting implicitly outputs a newline, that is not the case in Twue, which must manually insert the newline.

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

Duocentehexaquinquagesimal, 18 bytes

hùyy₄āÆβUW:“ã¾8½ž+

Try it online!

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

BRASCA, 14 bytes

l[ll['*o{]xo{]

Try it online!

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

yuno (abandoned), 11 bytes

」*10リュ」ニュア10リュ

xxd using Jelly's codepage:

00000000: f8f6 e6e5 5bf8 5200 e6e5 5b              ẏẇȧẓ[ẏR¡ȧẓ[

Explanation

」*                push "*"
  10              push 10
    リュ            repeat "*" 10 times
      」ニュ         push "\n"
         ア        add / concatenate
          10      push 10
            リュ    repeat "**********\n" 10 times

Equivalently written as ]*10ryu]nyua10ryu

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

Mathematica, 24 bytes

Print@@@Table["*",10,10]

A second (simple) Mathematica proposition, same length

\$\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\$
    – hyperneutrino
    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\$

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\$
    – rydwolf
    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\$

Swift, 54 bytes

for _ in 0...9 {print(String(repeating:"*",count:10))}

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\$

+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\$
1
\$\begingroup\$

Arturo, 27 bytes

10|loop=>[repeat{*}10print]

Try it!

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

Among Us, 170 bytes

ORANGE SUS SUS RED SUS LIME SUS BLUE SUS SUS PINK SUS ORANGE SUS VENTED VENTED WHO PURPLE SUS GREEN SUS SUS SUS SUS SUS SUS SUS SUS SUS SUS BLUE SUS GREEN SUS SUSSY WHERE

Try it online!

Explanation

ORANGE SUS SUS               A1 += 10 2x (A1 = 20)
RED SUS                      A1 += 1 (A1 = 21)
LIME SUS                     A1 *= 2 (A1 = 42 = '*')
BLUE SUS SUS                 PUSH A1 2x
PINK SUS                     A1 = 0
ORANGE SUS                   A1 += 10 (A1 = 10 = '\n')
VENTED VENTED                A2 += 10 2x (A2 = 20)
                             (now A1=10, A2=20, stack=[42, 42])

WHO                          while (A2 != stack_top) {
PURPLE SUS                       POP
GREEN SUS SUS SUS SUS SUS        print(stack_top) 10x
      SUS SUS SUS SUS SUS        
BLUE SUS                         PUSH A1
GREEN SUS                        print(stack_top)
SUSSY                            A2 -= 1
WHERE                        }
\$\endgroup\$
1
\$\begingroup\$

Mindustry, 71 bytes

set i
print "**********\n"
op add i i 1
jump 1 lessThan i 10
printflush

Requires a processor connected to a message block, which is used as stdout.

\$\endgroup\$
2
  • \$\begingroup\$ Did not expect to see Mindustry here, pleasantly surprised! \$\endgroup\$
    – Mayube
    Commented Oct 11 at 15:35
  • 1
    \$\begingroup\$ Thanks, I'll try to write more Mindustry answers over the next days. I was actually surprised no one had done it before. \$\endgroup\$
    – Dornteufel
    Commented Oct 11 at 18:52

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.