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
5 6
7
8 9
14
2
\$\begingroup\$

05AB1E, 7 bytes

'*T×TF,

Try it online!

'*T×TF,  # full program
'*T×     # push "**********"
    TF   # repeat 10 times...
      ,  # output top of stack to STDOUT
         # (implicit) exit loop

05AB1E, 7 bytes

'*т×Tä»

Try it online!

'*т×Tä»  # full program
      »  # join....
  т×     # 100...
'*       # asteriks...
     ä   # split into...
    T    # 10...
     ä   # pieces...
      »  # by newlines
         # implicit output
\$\endgroup\$
2
\$\begingroup\$

CSASM v2.3.0.1, 50 bytes

func main:
push "**********\n"
push 10
mul
print
ret
end

mul duplicates a <str> value by a given <i32> amount, concatenating the copies together

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

GFortran, 31 29 bytes

print'(10A)',('*',j=0,99)
end

The loop ('*',j=0,99) spits out 100 *s. Formatting directive '(10(A))' '(10A)' wraps it.

try it online!

31 bytes

\$\endgroup\$
2
  • \$\begingroup\$ this shows that (fortran.ge.javascript) \$\endgroup\$
    – roblogic
    Commented Mar 15, 2021 at 1:22
  • 1
    \$\begingroup\$ FWIW Gnu f95 doesn't is happy with this print'(10A)',('*',j=0,99) as the print line, meaning it does the right thing with 10A instead of 10(A), which drops 2 more characters. \$\endgroup\$
    – cnamejj
    Commented Mar 24, 2021 at 6:39
2
\$\begingroup\$

PHP, 69 Bytes

<?for($i=1;$i<101;$i++){if($i%10!=0){echo('*');}else{echo('*<br>');}}
\$\endgroup\$
1
2
\$\begingroup\$

Vyxal, 8 bytes

\*₀*¶+₀*

Try it Online!

-1 due to cairdcoinheringaahing

Later I reduced another one

\$\endgroup\$
4
  • 1
    \$\begingroup\$ -1 byte \$\endgroup\$ Commented Apr 25, 2021 at 17:19
  • \$\begingroup\$ @cairdcoinheringaahing thax! \$\endgroup\$
    – Wasif
    Commented Apr 25, 2021 at 17:20
  • \$\begingroup\$ here's how to do it in 4 bytes. But I recommend you keep this because it is flagless \$\endgroup\$
    – lyxal
    Commented Apr 26, 2021 at 2:36
  • \$\begingroup\$ Flagless, ₀(\*₀*, \$\endgroup\$
    – emanresu A
    Commented May 14, 2021 at 8:54
2
\$\begingroup\$

Barrel, 14 13 bytes

^42#10(#10p¶

Explanation:

^42          // push 42 to the accumulator
   #10       // do 10 times...
      (      // defines a code block which becomes a single instruction
             // (the parenthesis is self-closing)
       #10p  // print the accumulator as an ASCII character 10 times
           ¶ // print a newline

EDIT: removed the closing parenthesis, saving 1 byte, since I found the reason hadn't been able to get it to work right (I had added a newline at the end of my test file! *sigh*).

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

PPL, 33 bytes

loop10{
printLine("**********")
}

There is no concept of repeating strings, and the * operator is not overloaded with strings by numbers, so I hardcoded a string of 10 asterisks and printed it 10 times using the loop keyword.

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

Yggdrasil, 105 bytes

;*  
""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""""

Try it online!

The first few characters set up the memory tree for the program:

   ;
  / \
 *  \n

Yggdrasil has the = command for loops, but it unfortunately doesn't work. The only looping it can do is recursively call itself until it hits the recursion limit, so we have to print everything manually. The " command prints the left branch, which is *, and the : command prints both the left and the right branches, which are *\n

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

Deorst, 17 bytes

la
!o*
ERj
E;la
*

Try it online!

Explanation:

la    # Push 10
!     # For each 1..10:
 o*   #   Push '*'
ER    # Reverse stack
  j   # Convert 10 to char (\n)
E;    # Concatenate stack
  la  # Push 10
*     # Multiply
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

Vyxal j, 8 7 5 bytes

-1 byte cause map lambdas are awesome.
-2 bytes thanks to the j flag

My first attempt at Vyxal.

\*₁*²

Explanation

\*         - Push "*"
  ₁*       - Repeat 100 times
    ²      - Format as a square
<flag>     - Join by newline
<implicit> - Print it

Try it Online!

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

Subleq (8 bit), 18 bytes

 2 -1 42
 1 17  0
15 -1 -9
15 17 12
 1  8  0
10 10 -9

Explanation

 2 -1 42 Print [2]                               // [2] = 42, ASCII(42) = "*"
 1 17  0 [17] = [17] - [1]  if [17] <= 0 goto 0  // Loop 10 times
15 -1 -9 Print [15]                              // [15] = 10 ASCII(10) = <line feed> 
15 17 12 [17] = [17] - [15] if [17] <= 0 goto 12 // Set [17] back to -9
 1  8  0 [8]  = [8]  - [1]  if [8]  <= 0 goto 0  // Loop 10 times
10 10 -9 [10] = [10] - [10] if [10] <= 0 Exit    // Exit program
\$\endgroup\$
2
\$\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
2
\$\begingroup\$

APOL, 23 bytes

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

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

tinylisp, 49 bytes

(load library
(join(repeat-val(q **********)10)nl

Try it online!

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

Regenerate, 13 bytes

(\*{10}
){10}

Attempt This Online!

Explanation

(\*{10}\n){10}
 \*             Literal asterisk
   {10}         Repeated 10 times
       \n       Followed by a newline
(        )      All of that
          {10}  Repeated 10 times
\$\endgroup\$
2
\$\begingroup\$

BQN (CBQN), 14 bytes

•Out˘10‿10⥊"*"

Attempt This Online!

Explanation

•Out˘10‿10⥊"*"
            "*"  String (1-dimensional character array) containing an asterisk
     10‿10⥊     Reshape into a 10 by 10 array of asterisks
    ˘            For each row:
•Out               Print with a trailing newline
\$\endgroup\$
2
\$\begingroup\$

Vyxal, 4 bytes

₀₀×ŀ

Try it Online!

   ŀ # Make a grid of size
₀    # Ten
 ₀   # By ten
  ×  # Filled with asterisks
\$\endgroup\$
1
2
\$\begingroup\$

Brachylog v1, 15 bytes

9ye,"*":9jw@Nw\

Try it online!

Explanation

This exploits backtracking to loop; we create ten useless choice points at the beginning so that it writes ten times the string "**********\n".

9ye,         Pick a number between 0 and 9 (there are thus 10 choice points here)
"*":9j       Concatenate "*" 9 times to itself
w@Nw         Write that string and write a line break
\            False (trigger backtracking: pich another one of the ten numbers)
\$\endgroup\$
2
\$\begingroup\$

Brachylog, 11 bytes

"*"j₁₀ẉ₂ⁱ¹⁰

Try it online!

Explanation

"*"j₁₀ẉ₂ⁱ¹⁰
"*"          Asterisk
   j₁₀       Join 10 copies together into one string
        ⁱ¹⁰  Repeat 10 times:
      ẉ₂      Write (with trailing newline; predicate output = input)

Alternately, it's possible to port Fatalize's Brachylog v1 solution in 11 bytes:

Ḋ≜∧"*"j₁₀ẉ⊥
Ḋ≜            Pick some number 0 to 9
  ∧           Its value doesn't matter, it just matters that we picked it
    "*"       Asterisk
       j₁₀    Join 10 copies together into one string
          ẉ   Write (with trailing newline)
           ⊥  Force backtracking
\$\endgroup\$
2
\$\begingroup\$

Rattle, 13 bytes

*|![[b]10B]10

Try it Online!

Explanation

*|                    take "*" as a variable
  !                   disable implicit output
   [ ......... ]10    loop 10 times
    [ ... ]10         loop 10 times
       b              concatenate "*" to buffer
             B        print and reset buffer      
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

TypeScript's Type System, 71 bytes

type F<A extends{}[]=[]>=A extends{length:10}?A:F<[...A,"**********"]>;

Try it at the TypeScript playground!

Just barely longer than Java :)

Type F recursively appends "**********" to array A until A's length is 10.


If you need the output to be a string and not a list of lines, here's an 83 byte version:

//@ts-ignore
type F<A=[],S="">=A extends{length:10}?S:F<[...A,1],`${S}
**********`>

Try it at the TypeScript playground!

This one recursively appends "\n**********" to string S while appending 1 to array A until A's length is 10. We need to do it like this because you can't get the length of a string in TypeScript's type system without converting it to a list first, so it's shorter to have a list just to keep track of iteration.

The //@ts-ignore is necessary because the compiler doesn't want to spread A, which it can't tell is a list, or inject S, which it can't tell is a string, into the main string. We could explicitly tell the compiler that A extends{}[] (A is a list of something) and that S extends string, but that comes out to be a lot longer than just ignoring the errors.

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

Civet, 33 bytes

console.log '**********'for[0..9]

Compiles to this JS:

for (let i = 0; i <= 9; ++i) {
  console.log("**********");
}

Playground link

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

Acc!!, 48 43 bytes

-5 thanks to @DLosc

Count i while i-110 {
Write 42-i%11/10*32
}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Here's 43 bytes. \$\endgroup\$
    – DLosc
    Commented Aug 4 at 20:21
1
\$\begingroup\$

Batch, 41 bytes

@for /l %%i in (0,1,9)do @echo **********
\$\endgroup\$
8
  • \$\begingroup\$ You can shave off 1 byte by removing the first @ \$\endgroup\$ Commented Aug 6, 2016 at 3:44
  • \$\begingroup\$ @SomethingDark But then it would print for /l %%i in (0,1,9)do @echo **********... \$\endgroup\$
    – Neil
    Commented Aug 6, 2016 at 9:39
  • \$\begingroup\$ It didn't when I tested it \$\endgroup\$ Commented Aug 6, 2016 at 9:39
  • \$\begingroup\$ @SomethingDark You mean as an immediate command? As it's a single line, you might be on to something there. \$\endgroup\$
    – Neil
    Commented Aug 6, 2016 at 9:45
  • \$\begingroup\$ As both an immediate command (in which case you could save an additional byte by using %i instead, but I need to double-check the rules for this language) and in a script. \$\endgroup\$ Commented Aug 6, 2016 at 9:46
1
\$\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
1
\$\begingroup\$

BASH, 46 bytes

for((n=0;n<10;n++));do echo "**********"; done
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Or for n in {0..9};{ echo "**********";} \$\endgroup\$
    – manatwork
    Commented Aug 4, 2016 at 12:43
  • \$\begingroup\$ Or seq -f%10g 10|tr -c \\n \* in Bash + coreutils. \$\endgroup\$
    – manatwork
    Commented Aug 4, 2016 at 14:52
1
\$\begingroup\$

Frink, 40 39 Bytes

for r=0 to 9
  println[repeat["*",10]]

-1 Byte @LeakNun

\$\endgroup\$
1
  • 4
    \$\begingroup\$ You can probably use 0 to 9 \$\endgroup\$
    – Leaky Nun
    Commented Aug 4, 2016 at 11:18
1
\$\begingroup\$

Maple 30 bytes

printf(cat("**********\n"$10))
\$\endgroup\$
1
5 6
7
8 9
14

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.