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

411 Answers 411

1
10 11 12 13
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\$

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\$

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, 2018 at 17:55
  • \$\begingroup\$ (also, does this language exist online anywhere?) \$\endgroup\$ Sep 28, 2018 at 17:56
  • \$\begingroup\$ @ETHproductions Nesting @rep is explicitly not allowed in the game's docs. Link added in header. \$\endgroup\$ Sep 28, 2018 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, 2018 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, 2021 at 20:56
  • \$\begingroup\$ @EasyasPi I try to make it portable \$\endgroup\$ Jan 25, 2021 at 15:32
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\$

Python 3 (23 bytes)

print(('*'*10+'\n')*10)
\$\endgroup\$
1
  • \$\begingroup\$ 23 bytes - I believe '\n' is two bytes of code, but if you measured with len it will have said 22. \$\endgroup\$ Aug 7, 2016 at 6:16
0
\$\begingroup\$

Swift, 54 bytes

for _ in 0...9 {print(String(repeating:"*",count:10))}

Try it online!

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

X86-64/Linux Machine Code, 32 bytes

Try it online!

Usage:

$> gcc -s -static -nostartfiles -nodefaultlibs -nostdlib -Wl,--build-id=none print.S -o print
$> ./print

Notes:

  • Size is measured in machine code (i.e 32 bytes of PROGBITS; .text, .data, etc...)
  • -4 more bytes without EXIT_CLEANLY (it will segfault to exit).
/* Comment out EXIT_CLEANLY to save 4 bytes. */
#define EXIT_CLEANLY

    .global _start
    .text
_start:
    /* Incoming registers are zero.  */

    /* Use stack for storage.  */
    push    %rsp
    pop %rsi

loop:
    /* '*' in output buffer.  */
    movb    $0x2a, (%rsi)

    /* First round we have SYS_read + length 0 which is essentially
       a nop.  */
    syscall
    /* Assuming no IO error, read(0) will return 0.  */

    /* bh is initially 0, so this won't loop in initial fallthrough.  */
    decb    %bh
    jg  loop

    movb    $0xa, %bh   /* 0xa == '\n'. */
    movb    %bh, (%rsi)
    /* Initial round this will be a nop, same as above.  */
    syscall
    /* SYS_write.  */
    movb    $1, %al
    /* STDOUT.  */
    movl    %eax, %edi
    /* 1-byte at a time.  */
    movb    $1, %dl

    /* After 10 iter this will have signed overflow.  */
    addb    $0xc, %bl
    jns loop
#ifdef EXIT_CLEANLY
    /* Exit.  */
    movb    $60, %al
    syscall
#endif
```
\$\endgroup\$
0
\$\begingroup\$

morsecco: 109 bytes

The shortest way seems to be to define a new command repeating a given string a given times:

.  . .- .- --.. .. - -. - . -. -.-. . ..  . -. .-- . -.-.-. -.- - . -.-. -. . -.-. -.- - -.-. . . -.-. -. ---

The command itself is only 37 bytes:

  • . .- .- to decrement the number (Enter minus 1 and Add)
  • --.. .. to Zeroskip to the .., leaving the input string
  • - -. - . we need some stack juggling to duplicate the next of stack (over and swap)
  • -. is the recursive call with the decremented number
  • -.-. . Concatenates the returned string from the command to itself
  • .. is currently not used, so it can currently be used as a skip target. This may fail in future versions of morsecco

Unfortunately, the surrounding code is twice as long:

  • . -. .-- Writes the code to address -.
  • . -.-.-. -.- - Enter 42 and Konvert to Text
  • . -.-. -. Enter 10 and call the new command
  • . -.-. -.- - -.-. . add the newline to the string; expensive, but necessary
  • . -.-. -. --- call the new command again with 10 and Output

Fun fact: this is the length of the challenge output (100 stars plus 9 newlines). Always keep in mind that morsecco wastes a factor 5 of bytes by restricting itself to only three symbols. With 22 real information bytes, it could compete.

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

Easyfuck, 24 21 bytes

ke#ä/DCSűWîUµŻ­­SHYSHY|ąĺÔ+ž]

due to lack of unicode representations for c1 control characters, they have been replaced by their superscripted abbreviations

Decompressed:

5Y$>!>!{+{J[->[->.<]!.<]
5Y$>!>!{+{J[->[->.<]!.<]
5Y                       set cell 1 to 80 (5*16) and flip the bit order setting it to 10
  $>!>!                  copy cell 1 to storage and set cells 2 and 3 to storage
       {+{               left-shift, increment, and left-shift again cell 3, setting it to 42
          J[           ] go to cell 1 and begin a while loop
            ->[    ]     decrement cell 1 and go to cell 2 to begin another while loop
               ->.<      decrement cell 2 and print cell 3 (42 is *)
                    !.<  set cell 2 to storage and print it (10 is new line)
\$\endgroup\$
0
\$\begingroup\$

YASEPL, 26 22 bytes

=l$11`1=f$42»;f,10<!-[
\$\endgroup\$
0
\$\begingroup\$

SQL (Oracle), 48 bytes

select'**********'from dual connect by level<11;
\$\endgroup\$
0
\$\begingroup\$

Acc!!, 48 bytes

Count i while i-110 {
Write 42-32*0^((i+1)%11)
}

Try it online!

\$\endgroup\$
0
\$\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\$
-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, 2016 at 16:45
  • 11
    \$\begingroup\$ This answer is valid and allowed, but it's also extremely boring and unimaginative. \$\endgroup\$
    – DJMcMayhem
    Aug 5, 2016 at 17:08
  • 1
    \$\begingroup\$ Ok, Can I post it in Markdown? \$\endgroup\$
    – Skxrda
    Aug 5, 2016 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, 2016 at 21:43
  • 2
    \$\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, 2016 at 16:12
1
10 11 12 13
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.