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
6 7
8
9 10
14
1
\$\begingroup\$

C#, 52 50 49 bytes

49 bytes : 'for(int i=0;i++<10;)Console.Write("**********\n")' (Thanks to Csharpie)

50 bytes : for(int i=0;i<10;i++)Console.Write("**********\n")

52 bytes : for(int i=0;i<10;i++)Console.WriteLine("**********")

Close with 70 bytes : Console.WriteLine(String.Concat(Enumerable.Repeat("**********\n",10)))

edit : Test here : Online C# Interactive compiler.

P.S : C# Interactive is there in Visual Studio/Roslyn for a long time, no one said the answer needs to compile into an executable, or that C# is limited to .NET's verbose BCL functions or that C# is limited to Windows. csi.exe would just be same in functionality as other (interpreted) languages' interpreters do (like PowerShell), which is the beauty of C#.

\$\endgroup\$
3
  • \$\begingroup\$ You might want to include a link to an online interpretter/compiler so we can test your code. e.g. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 5, 2016 at 13:10
  • \$\begingroup\$ This would work almost the same as csi.exe included in Roslyn, although the behavior might not be the same for all cases. \$\endgroup\$ Commented Aug 5, 2016 at 13:25
  • \$\begingroup\$ You can shorten it down a bit for(int i=0;i<10;i++) can be written as for(int i=0;i++<10;) \$\endgroup\$
    – CSharpie
    Commented Aug 8, 2016 at 19:38
1
\$\begingroup\$

Swift, 35 Bytes

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

MarioLANG, 101 99 95 bytes

Saved 2 bytes thanks to Martin Ender.

Try it Online!

+
++++)+<......(<
++====".======"
+>)+(()>...(.
+====(-=====) -
+++++[!))++ )[!
======#=======#

The left half sets the tape to 10 40 10

The second half increases the 40 to 42, then prints the 42 (*) 10 times, and a newline, and repeats that 10 times.

\$\endgroup\$
2
  • \$\begingroup\$ Link? – – – – – \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 17:01
  • \$\begingroup\$ @LeakyNun Sorry I completely forgot. Edited it in. \$\endgroup\$ Commented Aug 5, 2016 at 17:06
1
\$\begingroup\$

Convex, 10 bytes

A'**{A*N}%

Try it online!

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

Oracle SQL 11.2, 44 bytes

SELECT'**********'FROM v$bh WHERE rownum<11;
\$\endgroup\$
1
\$\begingroup\$

Grocery List, 72 bytes

G

number ten
v
z
v
P
s
u
c
l
number ten
l
b
c
p
u
n
s
e
x
u
c
p
b
n
s
e

Try it online

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

LaTeX, 122 110 105 bytes

-12 bytes thanks to @Leaky Nun
-5 bytes by changing package & document type

Or, if I'm allowed to skip the document class definition & setup, and just count the package import and for-loop code: 55 bytes.

I still need to check if there's another package that has a shorter loop syntax, but for now, this simply uses pgffor (from tikz) and a foreach:

\documentclass{book}\usepackage{tikz}\begin{document}\foreach\n in{0,...,9}{**********\par}\end{document}

Ungolfed:

\documentclass{book}
\usepackage{tikz}
\begin{document}
\foreach\n in{0,...,9}{**********\par}
\end{document}

Output (w/ free page number :) ): enter image description here

\$\endgroup\$
6
  • 1
    \$\begingroup\$ ********** is shorter than \foreach\n in{0,...,9}{*} \$\endgroup\$
    – Leaky Nun
    Commented Aug 14, 2016 at 13:54
  • \$\begingroup\$ Good point! Not sure how I missed that... Must've been too focused on getting the nested loop going :) Thanks! \$\endgroup\$
    – MH.
    Commented Aug 14, 2016 at 14:10
  • \$\begingroup\$ \\ is shorter than \par \$\endgroup\$
    – Leaky Nun
    Commented Aug 14, 2016 at 14:11
  • \$\begingroup\$ True, but then the result is no longer a proper grid as the first line will be indented. \$\endgroup\$
    – MH.
    Commented Aug 14, 2016 at 14:27
  • \$\begingroup\$ @MH. -- Here's a Link to the Plain TeX solution: overleaf.com/read/tpjsnrgsnnsb \$\endgroup\$
    – Joe85AC
    Commented Jun 5, 2020 at 15:43
1
\$\begingroup\$

Fortran, 68 51 49 bytes

Skimmed off 17 bytes, because who needs indents and spaces?

-2 bytes thanks to @Joffan

As a tribute to senior and the fact there was no Fortran answer yet. Well, now I know why: this is a pretty hard language to golf! Just one or two indents already take up more bytes than the shortest answer here :)).

program T
do i=0,9
print*,('*',j=0,9)
end do
end

Try it! (ideone)

I tried golfing it down by introducing a nested 'implied' do loop, but the newline character wasn't available until Fortran 2003. Also, it's insanely verbose...

\$\endgroup\$
3
  • \$\begingroup\$ Loops using 0,9 limits skim off another couple? And make the positive case for not using '**********' :-) \$\endgroup\$
    – Joffan
    Commented Aug 19, 2016 at 20:14
  • \$\begingroup\$ Thanks! Not sure how I didn't think of that. Must've had a temporary brain meltdown :/ \$\endgroup\$
    – MH.
    Commented Aug 19, 2016 at 21:00
  • \$\begingroup\$ @MH. I know I'm late, but program T print'(10(A))',('*',j=0,99) end is 41 bytes long and doesn't print a leading space :-) \$\endgroup\$ Commented Oct 15, 2019 at 2:58
1
\$\begingroup\$

GolfScript, 27 bytes

0{"**********\n"\1+.10<}do;

Try it online!

Explanation

0              # Push 0 onto the stack: counter
{
"**********\n" # Push 10 '*' and a newline character
\              # Moves the counter onto the stack
1+             # Increments the counter
.10<           # Check if it's smaller than 10
}do;           # Repeat until counter equals 10
\$\endgroup\$
7
  • 1
    \$\begingroup\$ You know, you can just do this \$\endgroup\$
    – Leaky Nun
    Commented Aug 28, 2016 at 19:26
  • \$\begingroup\$ I'm a newbie, I didn't know, thank you! \$\endgroup\$
    – FedeWar
    Commented Aug 28, 2016 at 19:27
  • \$\begingroup\$ Another byte saved \$\endgroup\$
    – Leaky Nun
    Commented Aug 28, 2016 at 19:28
  • \$\begingroup\$ 12 bytes now \$\endgroup\$
    – Leaky Nun
    Commented Aug 28, 2016 at 19:29
  • \$\begingroup\$ Wow, I still have a lot to learn. \$\endgroup\$
    – FedeWar
    Commented Aug 28, 2016 at 19:30
1
\$\begingroup\$

S.I.L.O.S, 41 bytes

Never used S.I.L.O.S before, can probably be golfed more.

EDIT: Looks like there was already a S.I.L.O.S answer, but it didn't show up on the leaderboard. But I'll keep this answer because it's shorter.

a=10
lblb
printLine **********
a-1
if a b

Try it online!

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

Japt, 9 bytes

Ao ç*pA)·

Test it online! This is, in fact, competing.

How it works

Ao ç*pA)·  // Implicit: A = 10
Ao         // Create the range [0..10).
   ç*pA)   // Fill with "*".repeat(A).
        ·  // Join with newlines. Implicitly print.
\$\endgroup\$
1
  • \$\begingroup\$ Can be 7 bytes these days! \$\endgroup\$
    – Shaggy
    Commented Feb 2, 2018 at 17:45
1
\$\begingroup\$

Sinclair ZX81/Timex TS1000/1500

Simple enough I think

Method 1, 55 bytes (listing):

 1 LET A=0
 2 PRINT "**********"
 3 LET A=A+1
 4 GOTO 2+((A=9)*3)

Method 2, 30 bytes (listing)

 1 FOR I=0 TO 9
 2 PRINT "**********"
 3 NEXT I
\$\endgroup\$
1
  • \$\begingroup\$ The ZX81 has a 1-byte ** (which is shift and H); this will save 5 bytes from each listing and might even be a bit quicker. ** is used for to the power of. \$\endgroup\$ Commented Feb 17, 2017 at 12:29
1
\$\begingroup\$

Syms 1.3, 17 bytes (noncompeting)

{*}10;*{
}~+10;*>

Explanation:

{*}10;*{\n}~+10;*>
{*}                 Pushes "*"
   10;*             Repeats it 10 times.
       {\n}         Pushes \n.
           ~+       Adds it to the end of "*"*10.
             10;*   Repeats it 10 times.
                 >  Outputs.
\$\endgroup\$
1
  • \$\begingroup\$ 2 bytes can be saved with 1.4's single char string $. \$\endgroup\$ Commented Jun 22, 2017 at 15:32
1
\$\begingroup\$

LibreLogo, 21 bytes

Code:

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

Result:

enter image description here

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

MATLAB / Octave, 23 bytes

Code:

m=[eye(10) ''];m(:)='*'

Try It Online!

Result:

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
1
  • \$\begingroup\$ You can replace '*' by 42 to save a byte. Or use [ones(10)+41 ''] \$\endgroup\$
    – Luis Mendo
    Commented Jan 8, 2018 at 16:26
1
\$\begingroup\$

R 34 bytes

While not being elegant at all, it makes what expected in not that many bytes...

cat(rep("**********",10),sep="\n")

\$\endgroup\$
1
  • 2
    \$\begingroup\$ write(matrix('*',10,10),'',10,,'') is the same number of bytes with a slightly different approach. \$\endgroup\$
    – Giuseppe
    Commented Jun 7, 2017 at 19:28
1
\$\begingroup\$

05AB1E, 7 bytes

'*т×Tô»

Try it online!

An alternate solution to the 05AB1E one already provided.

Explanation:

'*т×Tô» 
'*      Push an asterisk
  т×    Repeat the asterisk 100 times: "***********..."
    Tô  Split it into pieces of 10.
      » Join with newlines.
        Implicit print.
\$\endgroup\$
1
\$\begingroup\$

q/kdb+, 19 13 bytes

Solution:

-1(2#10)#"*";

Example:

q)-1(2#10)#"*";
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Explanation:

-1(2#10)#"*"; / solution
         "*"  / the asterisk
        #     / take or reshape
  (2#10)      / list (10;10), 10 rows, 10 columns
-1           ; / print to stdout
\$\endgroup\$
1
\$\begingroup\$

Pyth, 6 bytes

Bet there's going to be a shorter Charcoal answer

VT*T"*

Explanation:

VT     Ten times
 *T"*  Output ten asterisks followed by a newline

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ ---nope :|--- yep \$\endgroup\$
    – ASCII-only
    Commented Sep 7, 2017 at 1:55
  • \$\begingroup\$ @ASCII-only why am i alive \$\endgroup\$
    – Stan Strum
    Commented Sep 7, 2017 at 2:11
1
\$\begingroup\$

Java 8, 73 62 bytes

o is a String passed to a Consumer

o->System.out.print("**********".replace("*", "**********\n"))
\$\endgroup\$
1
  • \$\begingroup\$ o->System.out.print("**********".replace("*", "**********\n")) \$\endgroup\$
    – Nevay
    Commented Sep 28, 2017 at 14:19
1
\$\begingroup\$

R: 33 bytes

write.matrix(matrix("*",10,10))

This does assume that you've loaded the MASS library.

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

Powershell, 78 bytes

$h=@();$v=@();1..10|% $_{$h+="*"};$i=0;Do{$v+=$h-join'';$i++}while($i-ne10);$v

Code explode:

$numbers = 1..10
$horArray = @()
$verArray = @()

Foreach ($number in $numbers){
    $horArray += "*"
}

$i = 0
Do {
    $verArray += $horArray -join ''
    $i++
}
while ($i -ne 10)
$verArray
\$\endgroup\$
1
\$\begingroup\$

Symbolic Python, 41 bytes

_=-~(_==_)
_=_**-~_+_
_=("*"*_+"""
""")*_

Try it online!

Explanation

  • _=-~(_==_) sets the value of _ to True, which is interchangeable with 1
  • _=_**-~_+_ performs 2**3+2, resulting in 10, and stores this in _
  • "*"*_ constructs a row, and +"""\n""" appends a newline.
  • This is multiplied by _, 10, to create the square.
  • At the end of execution, the value left in _ is printed.
\$\endgroup\$
1
\$\begingroup\$

Befunge, 33 bytes

55+:v
_v#:<,"*"-1
^_1-:!#@_55+:,1

Try It Online

How it works

55+:v
....<... Initialises the stack with two 10s as counters.
........ The first is for the outer loop, and the second is the inner

.....
_v#:<... Checks whether the inner counter is 0
._......

.....           If so, decrement the outer counter
_..........       If the outer counter is 0, exit the program
^_1-:!#@_55+:,1   Else print a newline and reset the outer loop counter

.....
.....,"*"-1 Else, decrement the inner counter and print an *
........... And run the inner loop again
\$\endgroup\$
1
\$\begingroup\$

Befunge-98, 19 15 bytes

a1_@#:-,ka:k8*'

Try It Online

First time using 98 instead of 93. Both the k and ' commands are immensely useful.

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

Kotlin, 41 bytes

Submission

fun f()=(0..9).map{println("**********")}

Test

fun f()=(0..9).map{println("**********")}

fun main(args: Array<String>) {
  f()
}

TryItOnline

Link

\$\endgroup\$
1
  • \$\begingroup\$ I believe lambda body is enough - 33 bytes \$\endgroup\$
    – mazzy
    Commented Jul 2, 2018 at 8:38
1
\$\begingroup\$

Thue, 30 bytes

%::=~**********
::=
%%%%%%%%%%

Try it online!


Thue, 53 bytes

%::=,*,*
>*::=>[
>,::=>]]
[::=~
]::=~*****
::=
>%%%%%

Uses the convention that "when a string is sent to the output stream, no newline is printed at the end, except if the string is empty, in which case a newline is all that is printed." This is not followed by the TIO interpreter.

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

Io, 32 bytes

10repeat("*"repeated(10)println)

Try it online!

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

Julia, 23 bytes

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

Explanation:

print(                ) # Print
      (           )     # A string consisting of 
       "*"^10           # "*" duplicated 10 times
             *"\n"      # then concatenated to a newline
                   ^10  # which is then duplicated 10 times
\$\endgroup\$
1
\$\begingroup\$

Canvas, 5 bytes

*A×A*

Try it online!

With notes (not valid code, as Canvas does not support comments):

          Print the following (implicit)
*         The string "*"
 A×      Duplicated 10 times horizontally
    A*  Duplicated 10 times vertically
\$\endgroup\$
1
6 7
8
9 10
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.