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

413 Answers 413

0
\$\begingroup\$

Javascript, 45 bytes

for(i=0;i<10;i++) {console.log('**********')}

even better, ES6 Javascript, 38 bytes

console.log('**********\n'.repeat(10))

open console and copy paste to test

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

Japt, 10 bytes

'*pA +R pA

Prints * ten times, then \n, then repeat from the beginning ten times.

Demo.

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

Arcyóu, 21 bytes

(* "**********\n" 10)

Try it online!

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

Gema, 31 characters

\A=@repeat{10;**********\n}@end

Sample run:

bash-4.3$ gema '\A=@repeat{10;**********\n}@end'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
2
  • \$\begingroup\$ Can you provide a link to anywhere? \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 11:01
  • \$\begingroup\$ Linkified the title, but I know about no on-line interpreter. :( \$\endgroup\$
    – manatwork
    Commented Aug 5, 2016 at 11:06
0
\$\begingroup\$

Groovy, 23 characters

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

Sample run:

bash-4.3$ groovy -e 'print(("*"*10+"\n")*10)'
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
\$\endgroup\$
0
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\$ Commented Aug 8, 2016 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\$ Commented Aug 5, 2016 at 20:12
  • \$\begingroup\$ @BusinessCat Thanks, do you know why this and this produce different results? \$\endgroup\$
    – Leaky Nun
    Commented Aug 6, 2016 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\$ Commented Aug 6, 2016 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\$ Commented Aug 18, 2016 at 12:45
  • \$\begingroup\$ Hey, thanks for the improvements @BusinessCat \$\endgroup\$
    – ʰᵈˑ
    Commented Aug 18, 2016 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
    Commented Aug 22, 2016 at 7:24
  • \$\begingroup\$ @manatwork Done. I'm new here; had no idea that was a thing. \$\endgroup\$
    – M. Justin
    Commented Aug 22, 2016 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\$ Commented Sep 12, 2016 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
    Commented Sep 12, 2016 at 8:38
  • \$\begingroup\$ 11 bytes off: print(("*"*10+"\n")*10) \$\endgroup\$ Commented Sep 12, 2016 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
    Commented Sep 12, 2016 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
    Commented Sep 12, 2016 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\$
    – Riker
    Commented Dec 27, 2016 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\$ Commented Feb 6, 2017 at 7:06
  • \$\begingroup\$ Unfortunately It seems to returns an invalid syntax error :\ \$\endgroup\$
    – GCaldL
    Commented Feb 9, 2017 at 1:57
  • \$\begingroup\$ Hm? It works for me. \$\endgroup\$ Commented Feb 9, 2017 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
    Commented Feb 9, 2017 at 23:29
0
\$\begingroup\$

Perl, 22 bytes

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

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.