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

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 88653; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
  • 2
    \$\begingroup\$ @DylanMeeus "You are to print this exact text:" \$\endgroup\$ – Leaky Nun Aug 4 '16 at 12:56
  • 13
    \$\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\$ – Trotski94 Aug 4 '16 at 12:58
  • 6
    \$\begingroup\$ @LeakyNun Leaderboard snippet please! \$\endgroup\$ – dkudriavtsev Aug 4 '16 at 22:08
  • 2
    \$\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
  • 1
    \$\begingroup\$ you say trailing new lines are acceptable. Are leading newlines acceptable too? \$\endgroup\$ – Albert Renshaw Feb 10 '17 at 2:34

270 Answers 270

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\$
  • \$\begingroup\$ Maybe i++<10 would help? \$\endgroup\$ – Matthew Roh 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\$ – Matthew Roh 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\$
  • \$\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\$ – Shaun Bebbers 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\$
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\$
  • \$\begingroup\$ range(10) works. \$\endgroup\$ – CalculatorFeline 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\$

05AB1E, 7 bytes

'*т×Tô»

Try it online!

An alternate solution to the 05AB1E one already provided.

Explanation:

'*т×Tô» 
'*      Push an asterisk
  т×    Repeat the asterisk 100 times: "***********..."
    Tô  Split it into pieces of 10.
      » Join with newlines.
        Implicit print.
\$\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\$
  • 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\$
  • \$\begingroup\$ incidentally, the ascii code for newline is 10, so: 10c \$\endgroup\$ – raddish0 Jun 9 '17 at 12:34
0
\$\begingroup\$

Check, 15 bytes

Non-competing as language postdates the challenge

"*">10:r*R]+R*o

Pushes the string * and repeats it ten times, while also storing 10 in the register. Then adds 10 to the end of the string (a newline), then repeats the whole thing 10 times.

\$\endgroup\$
  • \$\begingroup\$ Forgot to do that, sorry. \$\endgroup\$ – Esolanging Fruit Jun 15 '17 at 1:12
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\$

q/kdb+, 19 13 bytes

Solution:

-1(2#10)#"*";

Example:

q)-1(2#10)#"*";
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Explanation:

-1(2#10)#"*"; / solution
         "*"  / the asterisk
        #     / take or reshape
  (2#10)      / list (10;10), 10 rows, 10 columns
-1           ; / print to stdout
\$\endgroup\$
0
\$\begingroup\$

Pyth, 6 bytes

Bet there's going to be a shorter Charcoal answer

VT*T"*

Explanation:

VT     Ten times
 *T"*  Output ten asterisks followed by a newline

Try it online!

\$\endgroup\$
  • \$\begingroup\$ ---nope :|--- yep \$\endgroup\$ – ASCII-only Sep 7 '17 at 1:55
  • \$\begingroup\$ @ASCII-only why am i alive \$\endgroup\$ – Stan Strum Sep 7 '17 at 2:11
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\$

Symbolic Python, 41 bytes

_=-~(_==_)
_=_**-~_+_
_=("*"*_+"""
""")*_

Try it online!

Explanation

  • _=-~(_==_) sets the value of _ to True, which is interchangeable with 1
  • _=_**-~_+_ performs 2**3+2, resulting in 10, and stores this in _
  • "*"*_ constructs a row, and +"""\n""" appends a newline.
  • This is multiplied by _, 10, to create the square.
  • At the end of execution, the value left in _ is printed.
\$\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\$

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.