111
\$\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
    Aug 4 '16 at 12:56
  • 14
    \$\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
    Aug 4 '16 at 12:58
  • 7
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$
    – anna328p
    Aug 4 '16 at 22:08
  • 3
    \$\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
    Aug 5 '16 at 9:14
  • 1
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Feb 10 '17 at 2:34

367 Answers 367

1
9 10 11
12
13
0
\$\begingroup\$

Google Sheets, 22 Bytes

Anonymous worksheet function that takes no input and outputs a 10 x 10 grid of *s to the calling worksheet cell.

=REPT("**********
",10
\$\endgroup\$
0
\$\begingroup\$

ABCR, 36 bytes

)))))))BAAAAA4*xAb)))B(7OOOOOOOOOOP(x

Pushes 42 (the character code for *) to queue A, 10 (\n) to B, and then for each value from 9 to 0 print out ten copies of A as a character and one copy of B.

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

Acc!!, 68 bytes

Count i while i-10 {
	Count v while v-10 {
		Write 42
	}
	Write 10
}

Try it online!

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

dc, 41 bytes

[1-d0!>C]sR[42Pd10%0=NlRx]sC[10P]sN100lRx

Try it online!

I know there's dc answer, just wanna do it without dumping stack)

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

FALSE, 34 33 26 23 bytes

11[1-$]["**********
"]#
\$\endgroup\$
0
\$\begingroup\$

Momema, 44 bytes

a000b0-9 42 0+1*0b=+-10*0-9 10 1+1*1a=+-10*1

Try it online!

Explanation

                                                                     #  b = 0
a   0        #  label a0: jump past label a0 (no-op)                 #  do {
0   0        #            [0] = 0                                    #    a = 0
b   0        #  label b0: jump past label b0 (no-op)                 #    do {
-9  42       #            output chr 42                              #      print '*'
0   +1*0     #            [0] = 1 + [0]                              #      a += 1
b   =+-10*0  #  label b1: jump past label b((1 + !!([0] - 10)) % 2)  #    } while (a - 10 != 0)
-9  10       #            output chr 10                              #    print '\n'
1   +1*1     #            [1] = 1 + [1]                              #    b += 1
a   =+-10*1  #  label a1: jump past label a((1 + !!([1] - 10)) % 2)  #  } while (b - 10 != 0)
\$\endgroup\$
0
\$\begingroup\$

Micrsocript II, 13 bytes

{"*"s10*P}s9*
\$\endgroup\$
0
\$\begingroup\$

Python 3, 43 34 31 28 bytes

for i in[1]*10:print(10*'*')

Saved 9 bytes thanks to Simon

Saved 3 bytes thanks to Wheat Wizard

Just sprints ten asterisks and in a loop.

\$\endgroup\$
4
  • \$\begingroup\$ There is no need to print \n since each print starts with a new line. Also you can shorten 10*'*'. If you swap to Python 2, you can save another byte by removing a bracket. 31 bytes \$\endgroup\$
    – Simon
    Feb 6 '18 at 8:18
  • \$\begingroup\$ 30 bytes \$\endgroup\$
    – Simon
    Feb 6 '18 at 8:22
  • \$\begingroup\$ You can use something other than a range for example [1]*10 \$\endgroup\$
    – Wheat Wizard
    Feb 6 '18 at 22:45
  • \$\begingroup\$ If you do [1]*10 you don't need the space after in. \$\endgroup\$
    – Wheat Wizard
    Feb 12 '18 at 3:55
0
\$\begingroup\$

Whitespace, 91 bytes

[S S S T    T   S S T   S S N
_Push_100][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   T   S N
_If_negative_Jump_to_Label_EXIT][S S S T    S T S T S N
_Push_42_*][T   N
S S _Print_as_character][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S T T   _Modulo][N
T   S T N
_If_0_Jump_to_Label_NEWLINE][N
S N
N
_Jump_to_Label_LOOP][N
S S T   N
_Create_Label_NEWLINE][S S S T  S T S N
_Push_10][T N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer i = 100
Start LOOP:
  i = i - 1
  If(i < 0)
    Exit program
  Print "*"
  If(i modulo-10 == 0)
    Print new-line
  Go to next iteration of LOOP
\$\endgroup\$
0
\$\begingroup\$

Charm, 50 bytes

f := 10 repeat i
[ [ " * " pstring ] f newline ] f

Try it online!

Funnily enough, this doesn't use loops at all, just repeated code.

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

SNOBOL4 (CSNOBOL4), 56 50 bytes

O	OUTPUT =DUPL('*',10)
	X =LT(X,9) X + 1 :S(O)
END

Try it online!

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

C, gcc 36 bytes

recursive solution. One downside is you need to pass 2 when you call the function to get 10 rows. f(a){a<puts("**********")?f(a+1):0;}

This alternative addresses that issue and you don't have to call the function from main since main is now the recursive function:

main(a){a<puts("**********")-1?main(a+1):0;}

gcc also resolves #include "stdio.h" missing and variable a is implicitly set to an int and initialized to 0.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ You're not supposed to take input, I believe. \$\endgroup\$ May 26 '18 at 1:56
  • \$\begingroup\$ The second one addresses that. The second one is the entire .c file and takes no arguments when you run the executable. \$\endgroup\$
    – Geo
    May 26 '18 at 2:04
  • 2
    \$\begingroup\$ I see. You need to make that clear then(put the correct code in a code block under the header). \$\endgroup\$ May 26 '18 at 2:07
  • 2
    \$\begingroup\$ The solution you have at the top is an entirely invalid solution, so chuck it and just leave the valid one. \$\endgroup\$
    – LyricLy
    May 26 '18 at 4:55
  • \$\begingroup\$ Try it online! \$\endgroup\$ Jul 2 '18 at 15:16
0
\$\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\$
0
\$\begingroup\$

Pari/GP, 31 bytes

for(i=1,10,print("**********"))

Try it online!

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

Python 3, 28 bytes

print(*['*'*10]*10,sep='\n')

Try it online!

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

PHP, 60 45 Bytes

Try it online (original answer)

Try it online (saved 15 Bytes thanks to @Titus)

Code (Original)

<?=strtr(str_repeat(base_convert("1ku",36,2),10),["
","*"]);

Code (Titus suggestions)

<?=strtr(str_repeat(11111111110,10),10,"*\n");

About the edit

The change is, using str_repeat(base_convert("1ku",36,10),10) actually uses more bytes than str_repeat(11111111110,10) and the use of string for replacements on strtr instead of an array.

Explanation, Why "1ku"?`

The solution is repeat the string "**********", lets take the base 2 number 11111111110

base 10 = 2046
base  2 = 11111111110
base 36 = 1ku

Basically is repeat a compressed string, and with strtr replace each 1 with a "*" and 0 with a \n

\$\endgroup\$
3
  • \$\begingroup\$ Why don´t You just take a string with the bits instead of the packed number, and use strings instead of array for translation? 45 bytes: <?=strtr(str_repeat(11111111110,10),10,"*\n"); (decbin(2046) is one byte longer than that.) Nice idea though. \$\endgroup\$
    – Titus
    Jun 2 '18 at 11:46
  • 1
    \$\begingroup\$ (and while you´re at it, you can fix **strtr** to strtr ;-) \$\endgroup\$
    – Titus
    Jun 2 '18 at 11:48
  • \$\begingroup\$ I just realize that yeah, it's less bytes by using 11111111110 instead of base_convert("1ku", 36,10), i was trully focused on compress the string rather than check the byte count, gonna edit the answer, ty @Titus \$\endgroup\$ Jun 2 '18 at 18:14
0
\$\begingroup\$

Python 2, 21 bytes

exec'print"*"*10;'*10

Try it online!

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

Glee, 17 bytes

('*'%%10\)%%10,,\

Explanation:

('*'                          create '*'
    %%10                      reshape to length 10
        \)                    monadic segment with CRLF
          %%10                reshape to sequence length 10
              ,,\             expose with LF separators
\$\endgroup\$
0
\$\begingroup\$

Python 3, 22 bytes

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

Felt like entering a Python 3 program too.

\$\endgroup\$
0
\$\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
    Jul 2 '18 at 0:21
  • 1
    \$\begingroup\$ @CatWizard No need for main. Your proposal is already taken. \$\endgroup\$ Jul 2 '18 at 0:24
  • \$\begingroup\$ @CatWizard I am running GHCi on my terminal. Isn't that allowed? \$\endgroup\$ Jul 2 '18 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
    Jul 2 '18 at 0:42
  • \$\begingroup\$ @CatWizard I added a demo so that readers know this is to be used in an interpreter. \$\endgroup\$ Jul 2 '18 at 0:46
0
\$\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
0
\$\begingroup\$

Ahead, 21 18 bytes

~oK:k9*'N@k=11:+1~

Try it online!

\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

ESOPUNK, 167 78 77 bytes

MARK L
@REP 10
COPY 42 #STDO
@END
COPY 10 #STDO
TEST X = 9
ADDI X 1 X
FJMP L

I haven't been bothered to implement the preprocessor, but this should work when I do.

\$\endgroup\$
3
  • \$\begingroup\$ would it be possible to do an inner repetition? i.e. @REP 10 / @REP 10 / COPY 42 #STDO / @END / COPY 10 #STDO / @END \$\endgroup\$ Sep 28 '18 at 17:55
  • \$\begingroup\$ (also, does this language exist online anywhere?) \$\endgroup\$ Sep 28 '18 at 17:56
  • \$\begingroup\$ @ETHproductions Nesting @rep is explicitly not allowed in the game's docs. Link added in header. \$\endgroup\$ Sep 28 '18 at 18:34
0
\$\begingroup\$

Julia 1.0, 23 bytes

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

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can change the \n for a literal newline \$\endgroup\$
    – H.PWiz
    Dec 23 '18 at 13:54
0
\$\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\$
0
\$\begingroup\$

Pascal (FPC), 57 bytes

var i:word;begin for i:=0to 9do writeln('**********')end.

Try it online!

This is probably the best one as I don't see how this can be improved in 9 characters or less which could be gained by removing *s.

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

Assembly (NASM, 32-bit, Linux), 122 bytes

mov ecx,10
n:push 0xa202a2a
push '****'
push '****'
loop n
mov edx,120
mov ecx,esp
mov ebx,1
mov eax,4
int 128
add esp,120

Try it Online!

\$\endgroup\$
2
  • \$\begingroup\$ If you're scoring by assembler code and not machine code, use some NASM magic \$\endgroup\$
    – EasyasPi
    Jan 22 at 20:56
  • \$\begingroup\$ @EasyasPi I try to make it portable \$\endgroup\$ Jan 25 at 15:32
0
\$\begingroup\$

Java 11, 48 chars

Method String.repeat​(int)

for(int i=0;i++<10;out.println("*".repeat(10)));

Try it online!


Java 5, 53 chars

Static imports

for(int i=0;i++<100;out.print("*"+(i%10>0?"":"\n")));

Try it online!


Java 3, 60 chars

Plain old Java

for(int i=0;i++<100;System.out.print("*"+(i%10>0?"":"\n")));

Try it online!

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

Lua, 31 bytes

print(("**********\n"):rep(10))

Try it online!

Not very impressive but I think simpler is shorter in this case.

\$\endgroup\$
1
9 10 11
12
13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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