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

1
4 5
6
7 8
14
2
\$\begingroup\$

Keg, 10 bytes

(
|(
|\*)
)

Explanation

(\n|           Start for loop iterating 10 times
    (\n|       Start for loop iterating 10 times
        \*     Push an asterisk
          )    End loop
           \n  Push a newline

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Apparently the final ) is not needed, only the newline in front of it. At least for the TIO version. \$\endgroup\$
    – manatwork
    Commented Oct 14, 2019 at 14:20
2
\$\begingroup\$

JAPT, 12 bytes

'*
pA)+R
VpA

Japt sets vars automatically, so '* sets U to "*" pA)+R prints U out A(10) times. And adds a new line (+R). All this is set to V. VpA prints V out A times

In Regular JS is

U = "*";
V = (U.p(A)) + R;
V.p(A)
\$\endgroup\$
2
\$\begingroup\$

MAWP, 26 bytes

%25W[25W[~67W;~1A]%25W;1A]

This was interesting.

Try it!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You have no use for the % at the start and two stack reversals, essentially leading you to my answer codegolf.stackexchange.com/a/209467/92080 \$\endgroup\$
    – Dion
    Commented Aug 12, 2020 at 18:20
  • \$\begingroup\$ Really should stop spamming the stack reversal everywhere. \$\endgroup\$
    – Razetime
    Commented Aug 13, 2020 at 2:05
2
\$\begingroup\$

1+, 256 255 64 61 59 56 50 48 bytes

10
42
..(|(A|";";";";";)(A)^";^)(B|()()())(B)(B)

I'm lazy. Pushes a newline and an asterisk, then simply output them, without any tricks. No loops because creating terminating loops in 1+ is painful.

EDIT: -1 byte by reusing the constant 2.

EDIT: -191 bytes by using functions.

EDIT: -3 bytes by using another function.

EDIT: -2 bytes using one more function.

EDIT: -3 bytes.

EDIT: -6 bytes, although it probably doesn't quite follow the rules. It outputs number: followed by the correct output, but number: is a input prompt. If the input prompt have to be counted as output, then all answers with input is invalid as well.

This exploits a weird behaviour of the interpreter. When run in TIO with argument .input.tio, it reads from the input for the program source code and reads from the input again for the program input. So, yeah, the source code is fed into the input itself. 42 is a nope NOP because the only number literal 1+ recognises is 1. . pushes the input as an integer, which is 42.

If the character was something other than * it can be 46 bytes, by reading a character, not integer (* cannot precede the program due to the empty stack)

This will be completely valid after TwilightSparkle Edition is out. (TSE have a "-o" command line option that runs the original interpreter, except there are no prompts.)

EDIT: -2 bytes. Same trick with 10.

\$\endgroup\$
2
\$\begingroup\$

INTERCAL, 197 185 bytes

DO,1<-#11DO,1SUB#1<-#172DO,1SUB#11<-#260PLEASEREADOUT,1DO,1SUB#1<-#252PLEASEREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1DOREADOUT,1PLEASEGIVEUP

Try it online!

Looping is ~120 bytes longer...

Fills an array with tape instructions for one line, prints that, overwrites the first instruction with a new one relative to the new tape position, prints that nine more times.

EDIT

I used one PLEASE too much, also READ OUT and GIVE UP don't require a DO between the PLEASE and themselves, saving some bytes.

\$\endgroup\$
2
\$\begingroup\$

Rockstar, 53 51 41 37 35 bytes

X's10
while X
say "*"*10
let X be-1

Try it here (Code will need to be pasted in)

\$\endgroup\$
2
\$\begingroup\$

MAWP, 23 bytes

25W[25W[67W;1A]%52W;1A]

Try it!

Two nested loops doing almost the same thing

MAWP 2.0, 20 bytes

10[10["*":1-]`10;1-]

Try it!

Basically the same thing

\$\endgroup\$
2
\$\begingroup\$

Add++, 22 20 bytes

+42
y:10
Fy,Fy,,h,hy

Try it online!

Somehow -2 thanks to cairdcoinheringaahing

\$\endgroup\$
2
2
\$\begingroup\$

PyMin, 14 bytes / 10 characters

»("*"Ҁ+ѿ)Ҁ

Shorter version with v0.5:

13 bytes / 9 characters:

»("*"ҀƜ)Ҁ
\$\endgroup\$
1
  • \$\begingroup\$ The repository was deleted. \$\endgroup\$
    – user85052
    Commented Nov 7, 2019 at 10:07
2
\$\begingroup\$

Braingolf, 18 bytes

8V9R#*[.]#
[R&!@v]

Try it online!

Explanation:

8V9R#*[.]#\n[R&!@v]
8                    Push 8
 V                   Create stack2 and switch to it
  9                  Push 9
   R                 Return to stack1
    #*               Push codepoint of *
      [.]            Do-while loop, will run 9 times due to the 8 pushed at the start
       .             Duplicate last item on stack
         #\n         Push codepoint of newline
            [R...v]  Do-while loop, uses stack2 for loop counting
                     Will run 10 times due to the 9 pushed at the start
              &!@    Print entire stack1 without popping
\$\endgroup\$
1
  • \$\begingroup\$ 15 bytes \$\endgroup\$
    – Leaky Nun
    Commented Jun 16, 2017 at 8:00
2
\$\begingroup\$

Marbelous, 81 bytes

@0
0A
>0\/
--
&0@1
&10B
@0&0
@1/\@2
@3@2
--/\\\..@4
>0&1&1/\&2
&2\/--@4/\s*
@3
:s*
2A
{0

Marbelous is a language based on marble machines

this program is composed of 4 subparts :

the main loop

a while loop going from 10 to 0, realease &0, and wait for &1 to be released before continuing

@0
0A
>0 \/
--
&0
&1
@0

the 11(0B) generator

a structure sending 11 (0B) to the portal @2 when the synchroniser group &0 is released

.. @1
.. 0B
.. &0
@1 /\ @2

the printer

a while loop waiting for something in @2 it then print that value minus 1 asterisk finish by printing the ascii value of @2-1 (which is 10(\n) here) and release synchroniser &1

@3 @2
-- /\ \\ .. @4
>0 &1 &1 /\ &2
&2 \/ -- @4 /\ s*
@3

asterisk creator

board transforming the inputted marble into a 2A (ascii value of *)

:s*
2A
{0

used language built-in are :

  • .. is a noop
  • 00-FF initiate a marble with this value
  • @n (n from 0 to Z) is a portal which teleport the marble to another portal with the same value
  • &n (n from 0 to Z) is a synchroniser, hold the marble until all corresponding synchroniser (same n) are full
  • \/ is a trash can
  • /\ create a duplicate passing marble to it's left and right
  • marbles going out of the machine from the bottom are implicitly outputed
  • -- is a decrement
  • \\ is a right deflector, the marble go right
  • >n (n from 0 to Z) is a conditional, if marble > n then noop else go right

boards

it also uses a board, boards are created with :name at the start of a new line with name being anything you want, they have special built-in

  • }n (n from 0 to Z) input argument
  • {n (n from 0 to Z) returned output

Boards execution pause the caller execution until finished

interpretor

\$\endgroup\$
2
\$\begingroup\$

CJam, 8 bytes

'*A*N+A*

My first CJam answer!

Explanation:

'*          Push an asterisk
  A*        Multiply by 10
    N+      Add a newline
      A*    Multiply by 10
            Implicitly output
\$\endgroup\$
2
\$\begingroup\$

Notepad++, 15 13 keystrokes

*<Ctrl-Shift-R><Ctrl-A><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-A><Ctrl-D><Ctrl-Shift-R><End><Enter><Ctrl-Shift-P>

Saved two keystrokes by using a macro. Explanation to come.

Original code and explanation

*****<Ctrl-D><Del><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-D><Ctrl-A><Ctrl-D>→<Enter>

We start by inserting five asterisks. CtrlD duplicates this line, leaving the cursor at the end of the first line. Del removes the newline, so now we have a line of ten asterisks.

Four applications of CtrlD give us five lines of asterisks. Next, CtrlA CtrlD duplicates all five lines at once, but it doesn't include a newline between the copies:

**********
**********
**********
**********
********************
**********
**********
**********
**********

Fortunately, the first half is still selected, so if we press , the cursor will be immediately after the tenth asterisk on the too-long line, and we can add the missing newline with Enter.

\$\endgroup\$
2
\$\begingroup\$

GNU nano, 14 keystrokes

<C-6>*<C-K><M-:><C-U><C-U><C-U><C-U><C-U><M-:><M-;><C-K><M-;><M-;>

<C-X> refers to CTRL+X, <M+X> refers to META+X.

Explanation

<C-6>         Start a selection block
*             Type an asterisk (typing does not affect the selection by default)
              At this point, '*' is selected.
<C-K>         Delete the selection and put it into the cutbuffer. '*'
<M-:>         Start recording a macro
  <C-U> (5x)  Paste 5 times, text is now '*****'
<M-:>         Stop macro recording. Macro pastes 5 times now.
<M-;>         Run the macro, pasting 5 more '*'s. Text is now '**********'
<C-K>         Delete the current line and put it in the cutbuffer. '**********\n'
<M-;><M-;>    Run the macro twice, pasting '**********\n' 10 times

Betcha didn't know nano had macros?

Video demo (done in Termux because of visible keyboard, --ignorerc just ignores any RC files that may alter the behavior)

\$\endgroup\$
2
\$\begingroup\$

Batch, 42 bytes

@for /l %%a in (1,1,10) do echo **********
\$\endgroup\$
2
\$\begingroup\$

vJASS (Warcraft 3), 100 76 bytes

Using //! import zinc "<code_path>" command to exclude //! zinc and //! endzinc.


library q{real w;function onInit(){for(0<=w<10){BJDebugMsg("**********");}}}

Warcraft 3

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Would you mind slowing down a bit on updating your answers, maybe wait for an hour or so before doing some more? The recently active page is getting flooded with older questions because of the edits, and it'd be good to let it settle down a bit \$\endgroup\$ Commented Mar 11, 2021 at 22:44
  • \$\begingroup\$ @ChartZBelatedly oh, okay. Sorry for my unintentional spam. \$\endgroup\$ Commented Mar 11, 2021 at 22:47
  • \$\begingroup\$ No worries, just thought it'd be worth letting you know :) \$\endgroup\$ Commented Mar 11, 2021 at 22:48
2
\$\begingroup\$

Python 3, 23 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 39 bytes

cat(c("*","\n")[(0:219)%%21/10],sep='')

Don't know if R coercing indices to integer is commonly used, so thought it worth posting in case someone can do something extra with it!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Sure, navigating among so many answers is a nightmare, but different variations of doing this in R were extensively discussed here. \$\endgroup\$
    – Kirill L.
    Commented Mar 15, 2021 at 9:55
  • \$\begingroup\$ Fair point @KirillL. and I would have posted a comment but didn't have the reputation yet - ironically, posting the new answer has given me some of the reputation I need to do it... \$\endgroup\$
    – Nick B
    Commented Mar 15, 2021 at 21:17
2
\$\begingroup\$

05AB1E, 7 bytes

'*T×TF,

Try it online!

'*T×TF,  # full program
'*T×     # push "**********"
    TF   # repeat 10 times...
      ,  # output top of stack to STDOUT
         # (implicit) exit loop

05AB1E, 7 bytes

'*т×Tä»

Try it online!

'*т×Tä»  # full program
      »  # join....
  т×     # 100...
'*       # asteriks...
     ä   # split into...
    T    # 10...
     ä   # pieces...
      »  # by newlines
         # implicit output
\$\endgroup\$
2
\$\begingroup\$

CSASM v2.3.0.1, 50 bytes

func main:
push "**********\n"
push 10
mul
print
ret
end

mul duplicates a <str> value by a given <i32> amount, concatenating the copies together

\$\endgroup\$
2
\$\begingroup\$

GFortran, 31 29 bytes

print'(10A)',('*',j=0,99)
end

The loop ('*',j=0,99) spits out 100 *s. Formatting directive '(10(A))' '(10A)' wraps it.

try it online!

31 bytes

\$\endgroup\$
2
  • \$\begingroup\$ this shows that (fortran.ge.javascript) \$\endgroup\$
    – roblogic
    Commented Mar 15, 2021 at 1:22
  • 1
    \$\begingroup\$ FWIW Gnu f95 doesn't is happy with this print'(10A)',('*',j=0,99) as the print line, meaning it does the right thing with 10A instead of 10(A), which drops 2 more characters. \$\endgroup\$
    – cnamejj
    Commented Mar 24, 2021 at 6:39
2
\$\begingroup\$

PHP, 69 Bytes

<?for($i=1;$i<101;$i++){if($i%10!=0){echo('*');}else{echo('*<br>');}}
\$\endgroup\$
1
2
\$\begingroup\$

Vyxal, 8 bytes

\*₀*¶+₀*

Try it Online!

-1 due to cairdcoinheringaahing

Later I reduced another one

\$\endgroup\$
4
  • 1
    \$\begingroup\$ -1 byte \$\endgroup\$ Commented Apr 25, 2021 at 17:19
  • \$\begingroup\$ @cairdcoinheringaahing thax! \$\endgroup\$
    – Wasif
    Commented Apr 25, 2021 at 17:20
  • \$\begingroup\$ here's how to do it in 4 bytes. But I recommend you keep this because it is flagless \$\endgroup\$
    – lyxal
    Commented Apr 26, 2021 at 2:36
  • \$\begingroup\$ Flagless, ₀(\*₀*, \$\endgroup\$
    – emanresu A
    Commented May 14, 2021 at 8:54
2
\$\begingroup\$

Barrel, 14 13 bytes

^42#10(#10p¶

Explanation:

^42          // push 42 to the accumulator
   #10       // do 10 times...
      (      // defines a code block which becomes a single instruction
             // (the parenthesis is self-closing)
       #10p  // print the accumulator as an ASCII character 10 times
           ¶ // print a newline

EDIT: removed the closing parenthesis, saving 1 byte, since I found the reason hadn't been able to get it to work right (I had added a newline at the end of my test file! *sigh*).

\$\endgroup\$
2
\$\begingroup\$

Yggdrasil, 105 bytes

;*  
""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""":""""""""""

Try it online!

The first few characters set up the memory tree for the program:

   ;
  / \
 *  \n

Yggdrasil has the = command for loops, but it unfortunately doesn't work. The only looping it can do is recursively call itself until it hits the recursion limit, so we have to print everything manually. The " command prints the left branch, which is *, and the : command prints both the left and the right branches, which are *\n

\$\endgroup\$
2
\$\begingroup\$

Deorst, 17 bytes

la
!o*
ERj
E;la
*

Try it online!

Explanation:

la    # Push 10
!     # For each 1..10:
 o*   #   Push '*'
ER    # Reverse stack
  j   # Convert 10 to char (\n)
E;    # Concatenate stack
  la  # Push 10
*     # Multiply
\$\endgroup\$
2
\$\begingroup\$

Vyxal j, 8 7 5 bytes

-1 byte cause map lambdas are awesome.
-2 bytes thanks to the j flag

My first attempt at Vyxal.

\*₁*²

Explanation

\*         - Push "*"
  ₁*       - Repeat 100 times
    ²      - Format as a square
<flag>     - Join by newline
<implicit> - Print it

Try it Online!

\$\endgroup\$
2
\$\begingroup\$

INTERCAL, 109 bytes

Wait, no, I don't even need to make a loop.

PLEASE,1<-#11DO,1SUB#1<-#172DO,1SUB#11<-#260PLEASEREADOUT,1DO,1SUB#1<-#252DOREADOUT,1+,1+,1+,1+,1+,1+,1+,1+,1

Try it online!

INTERCAL, 116 bytes

mindoverflow said as if they can't loop shorter, but actually you can. The code below uses .1 as loop counter. Starting with .1<-512, iteration is done with DOCOMEFROM.1~.1 and (1)DO.1<-.1~#1022.

PLEASE,1<-#11DO,1SUB#1<-#172DO,1SUB#11<-#260DO.1<-#512DOCOMEFROM.1~.1PLEASEREADOUT,1DO,1SUB#1<-#252(1)DO.1<-.1~#1022

Try it online!

\$\endgroup\$
2
\$\begingroup\$

CLC-INTERCAL, 114 bytes.

From this how should I golf off....

DO;1<-#1DO;1SUB#1<-#121DO,1<-#1DO.1<-#512DOCOMEFROM.1~.1DOREADOUT;1+;1+;1+;1+;1+;1+;1+;1+;1+;1+,1(1)DO.1<-.1~#1022

Copy and paste to try it online!

\$\endgroup\$
1
  • \$\begingroup\$ No, I can't. Though I could do double-loops with DOSTASH.1DO.1<-#0 and DORETRIEVE.1, DOREADOUT, ~#1022, and some similar code appears twice, which makes it longer. \$\endgroup\$
    – user100411
    Commented Sep 16, 2021 at 12:42
2
\$\begingroup\$

Subleq (8 bit), 18 bytes

 2 -1 42
 1 17  0
15 -1 -9
15 17 12
 1  8  0
10 10 -9

Explanation

 2 -1 42 Print [2]                               // [2] = 42, ASCII(42) = "*"
 1 17  0 [17] = [17] - [1]  if [17] <= 0 goto 0  // Loop 10 times
15 -1 -9 Print [15]                              // [15] = 10 ASCII(10) = <line feed> 
15 17 12 [17] = [17] - [15] if [17] <= 0 goto 12 // Set [17] back to -9
 1  8  0 [8]  = [8]  - [1]  if [8]  <= 0 goto 0  // Loop 10 times
10 10 -9 [10] = [10] - [10] if [10] <= 0 Exit    // Exit program
\$\endgroup\$
1
4 5
6
7 8
14

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.