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
  • 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

377 Answers 377

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

Bc, 26 characters

for(;i++<10;)"**********
"

Sample run:

bash-4.3$ bc <<< 'for(;i++<10;)"**********
"'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
0
\$\begingroup\$

JavaScript (115 106 81 chars)

o='';
for(i=0;i<10;i++){l='';for(j=0;j<10;j++){l+='*';}o+=l+"\n";}
console.log(o);

\$\endgroup\$
1
  • \$\begingroup\$ make the program all one line, instead of using "\n", just use a literal newline by hitting enter inside two empty quotes. that should save you 4 bytes. Also, do you need a semicolon after `l+='*'? \$\endgroup\$ Aug 8 '16 at 1:38
0
\$\begingroup\$

ListSharp, 73 bytes

[FOREACH NUMB IN 1 TO 10 AS k]
{
STRG p=p+"**********"+<newline>
}
SHOW=p
\$\endgroup\$
0
\$\begingroup\$

3var, 27 26 bytes

1 byte thanks to Business Cat

iisiia+<*>aaaF[PPPPPPPPPPO]
aaamaiis*>iiF[PPPPPPPPPPO]

I don't how do nested loops marked by F.

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ 26 bytes aaamaiis*>iiF[PPPPPPPPPPO] \$\endgroup\$ Aug 5 '16 at 20:12
  • \$\begingroup\$ @BusinessCat Thanks, do you know why this and this produce different results? \$\endgroup\$
    – Leaky Nun
    Aug 6 '16 at 4:05
  • \$\begingroup\$ I don't know. I don't see anything in the docs about needing to put loops on a new line, though they do in their examples. Maybe it's an interpreter error? \$\endgroup\$ Aug 6 '16 at 5:03
0
\$\begingroup\$

Mumps, 26 Bytes.

F J=0:1:9 W "**********",!

As loops are fairly efficient (space-wise) in Mumps, I thought I'd see if the loop within a loop was shorter, but it was not; weighing in at 31 bytes:

F I=0:1:9{F J=0:1:9{W "*"} W !}

The braces are allowable loop delimiters in the InterSystems Cache version of Mumps that I use; at times they may save a byte or two golfing, but mostly they're just handy to have nested loops in a one-line routine.

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

Befunge '98, 31 bytes

a>:|>1++:9`#@_a,
v*'[^
>,v1
-v>
\$\endgroup\$
0
\$\begingroup\$

Factor, 30

10 [ "**********"print ] times

So verbose...

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

MSM, 19 bytes

.;;.;...;.;;.;..␍**

where is a newline.

. concatenates the two rightmost characters and ; appends a copy of the rightmost element to the end, so the first commands .;;.;... create one line **********␍ and the next commands ;.;;.;.. make 10 lines out of it.

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

Pip, 7 bytes

LtP'*Xt

Straightforward: Loop 10 times. Print string of 10 asterisks each time. Kinda disappointed that the simple way was the shortest...

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

Jade & CSS, 41 36 bytes

- for (x=0;x++<10;)
  **********<br>

Jade is a HTML pre-processor. I'm unsure if using this is breaking any rule or if I have to include something else in the byte count. This also beats my previous entry of 60 bytes.

See it on Codepen: http://codepen.io/409/pen/ZOPgdJ

Thanks to Business Cat for saving 5 bytes.

\$\endgroup\$
2
  • \$\begingroup\$ You can save 1 byte by doing x++<11; instead of x<11;x++. I think you can also omit the var. Also this makes a 10x11 grid, you need to change the 11 to 10. \$\endgroup\$ Aug 18 '16 at 12:45
  • \$\begingroup\$ Hey, thanks for the improvements @BusinessCat \$\endgroup\$
    – ʰᵈˑ
    Aug 18 '16 at 13:10
0
\$\begingroup\$

Groovy, 23 characters

10.times{println'*'*10}
\$\endgroup\$
2
  • \$\begingroup\$ Please use code block markup (indent each line with 4 spaces or enclose it between <pre> and </pre> tags) for your code, so scripts like Code Golf UserScript Enhancement Pack can insert the length beside the code. \$\endgroup\$
    – manatwork
    Aug 22 '16 at 7:24
  • \$\begingroup\$ @manatwork Done. I'm new here; had no idea that was a thing. \$\endgroup\$
    – M. Justin
    Aug 22 '16 at 7:26
0
\$\begingroup\$

Stata, 49 bytes

loc i=1
wh `i'<11 {
di "**********"
loc i=`i'+1
}

Output

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

ISOLADOS, 131 bytes

ISOLAADOOOOOOOOOOOS ISOLAAAAAAADOS ISOLAADOOOOOOOOOOS ISOLAAADOOOS ISOLAAAAAAAADOS ISOLAADOOOOOOOOOOS ISOLAAADOOOS ISOLAAAAAAAAADOS

ISOLAADOOOOOOOOOOOS    push 11
ISOLAAAAAAADOS         chr(a + 31)
ISOLAADOOOOOOOOOOS     push 10
ISOLAAADOOOS           push a * b
ISOLAAAAAAAADOS        push [a]
ISOLAADOOOOOOOOOOS     push 10
ISOLAAADOOOS           push a * b
ISOLAAAAAAAAADOS       join list by new lines
\$\endgroup\$
0
\$\begingroup\$

Racket 36 bytes

(for((j 10))(displayln"**********"))
\$\endgroup\$
0
\$\begingroup\$

Groovy 46 Bytes

(1..10).collect{''.center(10,'*')}.join('\n')

https://groovyconsole.appspot.com/script/5102912250314752

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

SX, 21 bytes

和(0,10):我('*'*10)

Actually: this compiles (technically, it just becomes Python) directly to Python. It is the same as:

for i in range(0,10):print('*'*10)

\$\endgroup\$
5
  • \$\begingroup\$ The SX code is 21 bytes long, and please split your answer in multiple answers for multiple submissions \$\endgroup\$ Sep 12 '16 at 8:37
  • \$\begingroup\$ Generally is better to post solutions in different languages in different answers, so they can be upvoted / downvoted separately. For example your Ruby solution is essentially identical with John Ramos's Ruby answer, so that may attract some downvotes. \$\endgroup\$
    – manatwork
    Sep 12 '16 at 8:38
  • \$\begingroup\$ 11 bytes off: print(("*"*10+"\n")*10) \$\endgroup\$ Sep 12 '16 at 8:39
  • \$\begingroup\$ @TùxCräftîñg, that would be duplicate of helloworld922's Python 3 answer (or if you make it Python 2, then duplicate of shooqie's answer). \$\endgroup\$
    – manatwork
    Sep 12 '16 at 8:53
  • \$\begingroup\$ I'm so sorry. I didn't even read any of the answers. I just answered. I'll delete my answers for Python and Ruby. \$\endgroup\$
    – XiKuuKy
    Sep 12 '16 at 12:39
0
\$\begingroup\$

Prolog (SWIPl), 64 / 69 bytes (depending on how to count)

-1*_.
A*0:-writeln(*),C is A-1,C*9.
A*B:-write(*),C is B-1, A*C.

Query with

9*9.

Online Example

Try it online, but take note that since writeln/1 has a bug in Swish, causing it to print a new line before as well as after. I've replaced it with write/1,nl/0 which should be (according to documentation) its equivalent. This raised the byte count of the example.

On the Byte Count

I'm not sure how to count the query, but if it is to be counted towards the total byte count, it's 5 bytes (including an Enter).

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

D2, 11 bytes

!7;//.|a:|a

Explanation:

!7 is expanded to 7 +, so it set the current cell to 7.
; switch to the second shift state (7 is *) /code|digit repeat code digit times (digit is base 36).
. print the character in the current shift state (so here, * is printed).
: print a newline in shift mode 2.

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

Stuck, 10 Bytes

Very simple implementation here, no tricks ;)

'*10*N+10*

Explanation:

'*           # Enter char mode, puts '*' on the stack
  10*        # Multiply string by 10, puts '**********' on the stack
     N+      # Push a newline to the stack and append to the asterisks
       10*   # Multiply that string by 10 and implicitly print.
\$\endgroup\$
0
\$\begingroup\$

memes, 17 bytes

d5+5’{p

Needs ********** as input, therefore +10.

d      Don't print result
5+5    10 times
’      loop
{p     Print input
\$\endgroup\$
0
\$\begingroup\$

Bash + coreutils + X11 term - 7 keystrokes

Exact keys to hit:

  • <Alt>+1
  • 0
  • 0
  • * (<Shift>+8)
  • <Return>

Requirements:

  • Your terminal window must be exactly 10 characters wide.
  • Your terminal prompt (PS1) should be empty.
  • Your working dir must be empty.
\$\endgroup\$
1
  • \$\begingroup\$ We count submissions like this in keystrokes, not bytes. So this would be 2 more keystrokes because of alt and shift. \$\endgroup\$ Dec 27 '16 at 16:04
0
\$\begingroup\$

8th, 28 bytes

( "*" 10 s:* . cr ) 10 times
\$\endgroup\$
0
\$\begingroup\$

Scala, 23 bytes

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

Almost the same as python solution.

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