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

Japt -R, 5 bytes

AÆAç*

Try it online!

Unpacked & How it works

Ao@Aç*

Ao@    Map range(10) with a function that returns...
Aç*      "*" repeated 10 times.
       `-R` flag joins the result array with "\n"
       Implicit output
\$\endgroup\$
1
\$\begingroup\$

Japt -R, 5 bytes

AÆAî*

Test it

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

Prolog (SWI), 62 59 55 54 bytes

t.
b:-between(0,9,_).
?-b,(b,write(*),1=0;t),nl,1=0;t.

Try it online!

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

Tcl, 25 bytes

time {puts **********} 10

Try it online!

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

Python 2, 20 bytes

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

I didn't know you could remove the space between print and the string.

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

Haskell, 34 bytes

putStr$[0..9]>>([0..9]>>"*")++"\n"

λ> putStr$[0..9]>>([0..9]>>"*")++"\n"
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
5
  • \$\begingroup\$ Since the question stipulates you have to print the text your likely need a main=. I'd also point out that "*********\n" is shorter than ([0..9]>>"*")++"\n". \$\endgroup\$
    – Wheat Wizard
    Commented Jul 2, 2018 at 0:21
  • 1
    \$\begingroup\$ @CatWizard No need for main. Your proposal is already taken. \$\endgroup\$ Commented Jul 2, 2018 at 0:24
  • \$\begingroup\$ @CatWizard I am running GHCi on my terminal. Isn't that allowed? \$\endgroup\$ Commented Jul 2, 2018 at 0:39
  • \$\begingroup\$ GHCi is allowed. It is generally considered a different language from Haskell. If other people are not using main and no one has done anything I think you will fine though. \$\endgroup\$
    – Wheat Wizard
    Commented Jul 2, 2018 at 0:42
  • \$\begingroup\$ @CatWizard I added a demo so that readers know this is to be used in an interpreter. \$\endgroup\$ Commented Jul 2, 2018 at 0:46
1
\$\begingroup\$

Powershell, 12 bytes

@('*'*10)*10

Explanation

  '*'*10      create a string with 10 '*'
@('*'*10)     create an array with one element of string with 10 '*'
@('*'*10)*10  repeat elements of this array 10 times
\$\endgroup\$
1
1
\$\begingroup\$

Matlab, 17 bytes

@()repmat('*',10)

Try it Online

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

ORK, 185 bytes

When this program starts:
I have a scribe called W
W is to write "**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********\n**********"

Try it online!

ORK does everything (even I/O and basic math) with objects. As far as this question goes, looping does not have to be one of them.

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

q, 12 bytes

10 10#get"*" / a 10x10 matrix
\$\endgroup\$
1
  • \$\begingroup\$ 10 10#(*) should have the same effect. But I'm not sure if spaces are allowed between asterisks. \$\endgroup\$
    – ngn
    Commented Sep 28, 2018 at 1:24
1
\$\begingroup\$

MBASIC, 32 bytes

1 WIDTH 10:PRINT STRING$(100,42)

RUN
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

No loop. Just printing 100 asterisks into a 10 character wide terminal to force line wraps.

There's no MBASIC on TIO, so I've linked the reference manual.

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

A0A0, 145 bytes

A0A0
A0C3G1G1G1G1G1G1G1G1G1G1G1A0
A0P42P42P42P42P42P42P42P42P42P42G3P10A0
A0A1G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3G-3A0
G-3
G-2G-2G-2G-2G-2G-2G-2G-2G-2

The top five lines are for the loop construction. A0A0 deletes instructions whenever it runs them, so those lines ensure that the loop keeps running. On line 3 are ten P42 instructions which print * (42 is the ascii code for an asterisk). The P10 instruction prints a new line.

The bottom line acts as a counter. For every execution of the loop it jumps to there and then jumps back to the loop. This consumes an instruction on that line. There are exactly nine instructions, so when it tries to go there when it has already printed ten lines the program will halt execution (since an empty line swill stop execution in A0A0).

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

Premier, 8 bytes

'*U*N+U*

Try it online!

The boring way.

Explanation

'*U*N+U*     full program
'*           push "*"
  U          push 10
   *         repeat
    N+       append newline
      U      push 10
       *     repeat

Premier, 14 bytes

QnN
**********

Try it online! This second approach uses Premier's implicit data iteration. It iterates over each character in the data (the second line), and executes the program (the first line) for each character. The data QnN pushes the data (Q), outputs it (n), then pushes a newline (N), to be implicitly outputted. This iterates 10 times, printing a 10x10 grid of asterisks.

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

Excel VBA, 11 Bytes

Anonymous VBE immediate window function that outputs a 10x10 grid of * to the ActiveSheet object

[A1:J10]="*
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 66 bytes

$x = 1x10;$x =~ s/\d/*/g;for($i = 1; $i <=10; $i++){print "$x\n";}

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You can remove literally all the whitespace \$\endgroup\$
    – Jo King
    Commented Feb 19, 2019 at 23:59
1
7 8
9
10 11
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.