112
\$\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
  • 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 '16 at 9:14
  • 3
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ Feb 10 '17 at 2:34

380 Answers 380

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

C++ 83 bytes 82 Thanks to matthew roh!

#include <iostream>
int main(){for(int i;i++<10;){std::cout<<"**********"<<"\n";}}

Try Me Online!

\$\endgroup\$
4
  • \$\begingroup\$ Maybe i++<10 would help? \$\endgroup\$ Feb 6 '17 at 7:06
  • \$\begingroup\$ Unfortunately It seems to returns an invalid syntax error :\ \$\endgroup\$
    – GCaldL
    Feb 9 '17 at 1:57
  • \$\begingroup\$ Hm? It works for me. \$\endgroup\$ Feb 9 '17 at 7:27
  • \$\begingroup\$ Amateur Mistake... As the last argument in a for statement I didn't expect ; was required etc. for(int i;i<10;i++) returns an error expected ')' before ';' when written as for(int i;i<10;i++;) \$\endgroup\$
    – GCaldL
    Feb 9 '17 at 23:29
0
\$\begingroup\$

Perl, 22 bytes

print"**********\n"x10
\$\endgroup\$
0
\$\begingroup\$

QC 41 bytes

&FF002A2A2A2A2A2A2A2A2A2A0D0AFF##########

&FF00 Write hex to memory at address 00 until FF is reached
2A2A2A2A2A2A2A2A2A2A0D0AFF 10 asterisks with a new line and the terminator at the end
########## Print contents of memory 10 times until first 00 is reached

Could be made shorter if loops were used.

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

Z80 TI-83+, 53 bytes

.nolist
#include "ti83plus.inc"
#define    ProgStart    $9D95

.list
.org    ProgStart - 2
    .db    t2ByteTok, tAsmCmp
    bcall(_homeup)
    ld A, 0
    ld (PenCol), A
Do:
    inc A
    ld hl, msg
    bcall(_PutS)
    bcall(_NewLine)
    cp 10
    jr NZ, Do
    ret
msg:
    .db "**********", 0
.end
.end

Compiled with SPASM.

\$\endgroup\$
0
\$\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\$ Feb 17 '17 at 12:29
0
\$\begingroup\$

Japt, 9 bytes

Ao@'*pA÷

Try it online!

Non-competitive solutions using the new flag features in Japt:

-R flag.

-x flag.

-Sx flags.

-P flag.

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

Cardinal, 41 bytes

%++=tt*=>"*******" v
        ^~?-~,"***"<

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 25 bytes \$\endgroup\$
    – Jo King
    Sep 18 '18 at 10:24
0
\$\begingroup\$

Syms, 24 bytes

{*}10;*[[[[[[[[[{~>[)}[)

The interpreter as provided errors immediately, but changing line 2 to if True: fixes it. (Is this allowed? Seems like it.)

Explanation:

{*}10;*[[[[[[[[[{~>[)}[)
{*}                       Add '*' to the stack.
   10;*                   Repeat it 10 times.
       [[[[[[[[[          Duplicate 9 times (there are now 10 copies on the stack)
                {~>[)}    Swap, output, duplicate, run (prints element below tos (top of stack) and then executes tos, stack is now (copies, this))
                      [)  Duplicate and run (causes infinite loop, exits when '*'*10 copies run out)
\$\endgroup\$
0
\$\begingroup\$

Python 3 (35 bytes)

for x in range(1,11):print("*"*10)
\$\endgroup\$
1
  • \$\begingroup\$ range(10) works. \$\endgroup\$ Mar 2 '17 at 22:13
0
\$\begingroup\$

RProgN 2, 8 bytes, Noncompeting

Noncompeting because Language Postdates challenge

°{°`**}*

I decided to take another stab at this, with a much better version of RProgN.

Explained

°{°`**}*
°      *    # Run the contained function Ten (Which ° is a constant for) times.
 {°  *}     # Repeat the referenced string 10 times.
   `*       # Asterisk Literal.
            # This results in 10 strings of 10 `*`s on the stack, which prints as expected.

Try it online!

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

Fourier, 22 bytes

10(10(~X42aX^~X)aN^~N)

Try it on FourIDE!

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

OCTAVE, 36 bytes

strrep(num2str(ones(10,10)),"1","*")

Makes a 10 by 10 matrix of ones, converts these to strings and then changes the ones to *'s.

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

OIL, 55 44 41 bytes, noncompeting

Annotated here for better understanding; remove everything after each ‌# in each line to make it work.

**********# asterisk storage
10#if what's in
14#line 14 (marked with $)
1#is identical to 10 (line 1)
13#jump to line 13 (marked with &)
6#else to line 6; the next line
4#print what's in line 0; 10 asterisks

11#print a newline
8#increment line 14 (marked with $)
14
6#jump to the beginning (line '' == line 0)

3#exit &
0#counter $
\$\endgroup\$
0
\$\begingroup\$

Syms 1.4, 12 bytes (noncompeting)

$
$*10*+10*>

Try it online!

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

C#, 96 bytes

static class P{static void Main(){for(int i=1;i<11;i++)System.Console.WriteLine("**********");}}

Try it online

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to PPCG! Firstly, you should specify the language and byte count; secondly, this isn't a full program or function, so doesn't meet the standard requirements; thirdly, you can save a bunch of bytes by removing unnecessary whitespace and changing the comparison symbol, like so: for(int i=1;i<11;i++)Console.WriteLine("**********\n"); \$\endgroup\$
    – F1Krazy
    Jun 9 '17 at 7:54
  • \$\begingroup\$ If this is C#, read this post to learn what your answer should be like. Also, have a look at the other answers to see what the standard format is (header with language name and bytecount, then code...). \$\endgroup\$
    – Dada
    Jun 9 '17 at 8:15
0
\$\begingroup\$

Micro, 15 bytes

"*"10*10c+10*:/
\$\endgroup\$
1
  • \$\begingroup\$ incidentally, the ascii code for newline is 10, so: 10c \$\endgroup\$
    – raddish0
    Jun 9 '17 at 12:34
0
\$\begingroup\$

k, 12 bytes

`0:10 10#"*"

Try it online.

Explanation:

   10 10#"*" /make 10 by 10 matrix of asterisk characters
`0:          /output each row as a line
\$\endgroup\$
0
\$\begingroup\$

4, 56 bytes

4, 5, 6!

3.600426011060310604018016021080250010202049503101010494

Try it online!

For explanation see verbose mode in the tio link - quite straightforward initialization of cells and nested 10x10 loop.

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

Crystal, 21 bytes

puts ("*"*10+"\n")*10
How does it work?
"*" * 10            = "**********" 
"**********" + "\n" = "**********\n"
"**********\n" * 10 = "**********\n**********\n[...]"
\$\endgroup\$
0
\$\begingroup\$

SOGL V0.12, 6 bytes

LL **∙

Try it Here!

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