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

419 Answers 419

1
\$\begingroup\$

Joeasus, 11 bytes

GRID 10 '*'

Try It Online!

You don't so much "Write" Joeasus answers as you do find them.

\$\endgroup\$
1
\$\begingroup\$

Red, 26 bytes

loop 10[print '**********]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Prolog (SWIPl), 63 / 68 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 the bug has been fixed.

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

C# - 88 bytes

class P{static void Main(){int i=0;while(i++<10)System.Console.Write("**********\n");}}
\$\endgroup\$
2
  • \$\begingroup\$ You can reduce this a bit by using a for look, putting int i inside it for(int i=10;i-->0;) (There is never a reason to use a straight while loop in C# code golf, a for loop is never more expensive) \$\endgroup\$ Commented Aug 4, 2016 at 17:24
  • \$\begingroup\$ I know, but then I would have been copying and pasting an already existing answer. \$\endgroup\$
    – pay
    Commented Aug 4, 2016 at 17:28
0
\$\begingroup\$

Perl, 24 bytes

print((("*"x10).$/)x10);

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

Javascript (using external library - Enumerable) (41 bytes)

_.From("**********\n").Cycle(120).Write()

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: This runs right in the console. Load the string into the library, which parses it to a char array enumerable. Create a new enumerable from that sequence, which is generated by cycling from start to finish 120 times (because the string length is 12, and we want 10 of them..12*10=120). I.e [1,2,3].Cycle(10) would be 1,2,3,1,2,3,1,2,3,1. Finally, join everything into a string with "" as delimiter

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ OH, .length lied to me ahah...I thought it would count "\" and "n" as separate characters..fixed! \$\endgroup\$ Commented Aug 4, 2016 at 17:58
  • \$\begingroup\$ Next time use mothereff.in/byte-counter \$\endgroup\$ Commented Aug 5, 2016 at 0:01
  • \$\begingroup\$ @PatrickRoberts Got it, thanks! \$\endgroup\$ Commented Aug 5, 2016 at 0:07
0
\$\begingroup\$

Ruby, 18 bytes

puts (?**10+$/)*10

Alternative version (+3 bytes)

10.times {puts ?**10}

Ungolfed (first version)

puts ('*' * 10 + '\n') * 10
\$\endgroup\$
1
0
\$\begingroup\$

Swift 2, 45 Bytes

func a(){for _ in 0...9{print("**********")}}
\$\endgroup\$
0
\$\begingroup\$

Wolfram, 22 bytes

Grid[Table["*",10,10]]
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to PPCG! I can't test right now, but I don't think this is a full program (it only displays correctly when used in Mathematica's notebook front end, which constitutes a snippet by this community's standards). If you put this in a source file and call it with wolfram -script file.m I don't think it'll print anything. I think the shortest way to get around that would be Print@@@Table["*",10,10]. Still, nice solution! :) \$\endgroup\$ Commented Aug 4, 2016 at 20:11
  • \$\begingroup\$ You are correct. Also, your solution works and is 24 bytes long. \$\endgroup\$ Commented Aug 4, 2016 at 20:29
0
\$\begingroup\$

R

matrix(rep("*",100), nrow = 10)

Probably faster way in R, but fun utilization of matrix

Explanation

rep: repeats first argument as many times as second argument.

matrix: creates matrix from vector (first argument), and nrow is the number rows desired in matrix.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hi, and welcome to PPCG! However, we require all code to be golfed, which this isn't. Please golf it. \$\endgroup\$
    – Riker
    Commented Aug 5, 2016 at 0:07
  • 1
    \$\begingroup\$ To make it print the actual desired output you would need to loop cat over it, one way or another. In addition, because of vector recycling, matrix("*",nr=10,nc=10) or array("*",c(10,10)) would be more concise to get the same matrix as the one you generate. \$\endgroup\$
    – plannapus
    Commented Aug 5, 2016 at 7:12
  • \$\begingroup\$ You are right in all regards. This works :for(i in 1:10){for (j in 1:10){cat("*");if(j == 10){cat("\n")}}} \$\endgroup\$
    – cgage1
    Commented Aug 5, 2016 at 16:54
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\$

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.