104
\$\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
  • 2
    \$\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\$ – Albert Renshaw Feb 10 '17 at 2:34

339 Answers 339

1
8 9 10 11
12
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\$ – Petr Fiedler Jan 25 at 15:32
0
\$\begingroup\$

Zsh -F, 19 bytes

yes **********|head

Try it online!

Edit: just saw this exact answer was already posted for bash :(

\$\endgroup\$
1
  • \$\begingroup\$ alt approach (22 bytes): jot -b'**********' 10 \$\endgroup\$ – roblogic Mar 15 at 1:55
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\$
0
\$\begingroup\$

x86_16 machine code - 37 bytes

B4 0E            MOV AH, 0EH
B9 000A          MOV CX, 10
8B D1            MOV DX, CX
8B D9            MOV BX, CX

             .LOOP:
B0 2A            MOV AL, "*"
CD 10            INT 10H
E3 02            JCXZ .NEWLINE
E2 F8            LOOP .LOOP

             .NEWLINE:
B0 0A            MOV AL, 10
CD 10            INT 10H
B0 0D            MOV AL, 13
CD 10            INT 10H

8B CB            MOV CX, BX
4A               DEC DX
74 02            JZ .EXIT
75 E9            JNZ .LOOP

             .EXIT:
B8 004C          MOV AX, 4C00H
CD 21            INT 21H

Running using DOSBox :

10-GRID Screenshoot

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

Java, 46 bytes

$->System.out.print("**********\n".repeat(10))

Try it online!

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

HTML, 136 bytes

**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********<br>**********
\$\endgroup\$
6
  • 2
    \$\begingroup\$ You can use <pre> \$\endgroup\$ – Leaky Nun Aug 5 '16 at 16:45
  • 9
    \$\begingroup\$ This answer is valid and allowed, but it's also extremely boring and unimaginative. \$\endgroup\$ – James Aug 5 '16 at 17:08
  • 1
    \$\begingroup\$ Ok, Can I post it in Markdown? \$\endgroup\$ – Skxrda Aug 5 '16 at 17:08
  • 3
    \$\begingroup\$ You can easily get this to 114 bytes with <pre> followed by the 109-byte text... \$\endgroup\$ – Timtech Aug 27 '16 at 21:43
  • 1
    \$\begingroup\$ I was hoping to join in on this one but unfortunately do not have the reputation for here yet. I'm not sure if this is an applicable method, but using html/emmet you can get this down to 20 bytes. ({**********}+br)*10 Alternatively p{**********}*10 is 16 bytes. New user to this site, so I'm unsure if the tab character counts. \$\endgroup\$ – N.J.Dawson Sep 1 '16 at 16:12
1
8 9 10 11
12

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.