Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Your challenge is to make an infinite loading screen, that looks like this:

enter image description here


Or, to be more specific:

  • Take no input.
  • Output Loading..., with a trailing space, but no trailing newline.
  • Infinitely cycle through the chars |, /, - and \: every 0.25 seconds, overwrite the last one with the next in the sequence. You can overwrite just the last character, or delete and rewrite the whole line, as long Loading... remains unchanged.

Rules

  • The output text must look exactly as specified. Trailing newlines/spaces are acceptable.
  • You should not wait 0.25 seconds before initially showing output - the first frame should be printed as soon as the program is run.
  • Your program should be able to run indefinitely. For example, if you use a counter for frames, the counter should never cause an error by exceeding the maximum in your language.
  • Although the waiting period between each "frame" should be 0.25 seconds, obviously this will never be exact - an error margin of 10% or so is allowed.
  • You may submit a function, but it must print to stdout.
  • You can submit an answer in a non-console (but still text-based) environment, as long as it is capable of producing the loading animation.
  • This is , so the shortest solution (in bytes) wins. Standard code-golf loopholes apply.
  • If possible, please provide a gif of your loading screen in action.

Example

Here is the C++ code I used to create the example (ungolfed):

#include <iostream>
#include <string>
#include <thread>

using namespace std;

int main() {
    string cycle = "|/-\\";
    int i = 0;

    cout << "Loading... ";

    while (true) {
        // Print current character
        cout << cycle[i];

        // Sleep for 0.25 seconds
        this_thread::sleep_for(chrono::milliseconds(250));

        // Delete last character, then increase counter.
        cout << "\b";
        i = ++i % 4;
    }
}

May the best golfer win!

share|improve this question
3  
Can submissions wait 0.25 seconds before initially displaying output? – ETHproductions Nov 27 at 20:42
    
No, but thanks for mentioning that, I'll add it to the rules @ETHproductions – Flp.Tkc Nov 27 at 20:43
    
Is a trailing newline (after the animating symbol) acceptable? – Copper Nov 27 at 20:43
    
Of course :) @Copper – Flp.Tkc Nov 27 at 20:44
    
@FlpTkc what if you have the slowest language ever? – Destructible Watermelon Nov 27 at 22:08

59 Answers 59

HTML/CSS, 183 180 163 161 160 bytes

a{display:inline-flex;vertical-align:top;overflow:hidden;width:1ch}c{animation:c 1s steps(4)infinite}@keyframes c{to{margin-left:-4ch
<pre>Loading... <a><c>|/-\

Edit: Saved 3 bytes thanks to @betseg. Saved 17 bytes thanks to @manatwork. Saved 1 byte thanks to @Daniel.

share|improve this answer
3  
According to meta, CSS+HTML is fine for answering questions. Furthermore I allowed this in the challenge description. So this answer is perfectly valid :) – Flp.Tkc Nov 27 at 21:30
3  
HTML+CSS is TC, so I don't see why it might be non-competing – TùxCräftîñg Nov 27 at 21:34
3  
@Artyer stackoverflow.com/a/5239256/3273184 is something worth considering. – Mama Fun Roll Nov 27 at 21:42
2  
@MamaFunRoll A comment on that post mentions that that doesn't really prove it TC because it can't loop without user intervention. However, it can solve this particular challenge, so I don't see any problem with this answer. – ETHproductions Nov 28 at 1:56
1  
@Neil you can remove last two braces and last semicolon in c to save three bytes. – betseg Nov 28 at 5:53

Vim, 43, 41 bytes

qqSLoading... |<esc>:sl250m
r/@:r-@:r\@:@qq@q

Two bytes saved thanks to @Udioica!

Here's a (slightly outdated) animation of it happening in real time!

enter image description here

And here is an explanation:

qq                              " Start recording into register 'q'
  SLoading... |<esc>            " Replace all of the text in the buffer with 'Loading... |'
                    :sl250m     " Sleep for 250 ms
r/                              " Replace the bar with a slash
  @:                            " Re-run the last ex command (sleeping)
    r-                          " Replace the slash with a dash
      @:                        " Re-run the last ex command (sleeping)
        r\                      " Replace the dash with a backslash
          @:                    " Re-run the last ex command (sleeping)
            @q                  " Run macro 'q' (the one we're recording)
              q                 " Stop recording
               @q               " Call macro 'q', which will run forever because it's recursive
share|improve this answer
1  
just curios: does it violate "Your program should be able to run indefinitely"? can it eventually reach a stack overflow? :) – dahn oak Nov 28 at 17:11
1  
@dahnoak Well, obviously I can't infinitely test it, but it doesn't allocate any extra memory, so I can't see any reason it wouldn't work indefinitely. – DrMcMoylex Nov 28 at 17:14
1  
If you switch i to S and move it inside the macro, you can skip r|. – udioica Nov 28 at 20:46
    
@udioica Thanks! – DrMcMoylex Nov 28 at 20:53
2  
@dahnoak There is no reason why the vi engine couldn't notice the tail recursion. And some implementations of recursion would do so naturally (imagine if there is a vector of commands to-be-executed, and a current execution location. Then @q would insert at-current-location the contents of register script q. No stack needed, and no memory allocated unless there are commands to run after @q within q.) – Yakk 2 days ago

HTML + JS (ES6), 20 + 51 50 = 70 bytes

setInterval(_=>a.innerHTML='|/-\\'[i=-~i%4],i=250)
Loading... <a id=a>/

-1 byte (Zachary T)

Check out my 132 byte HTML/CSS answer as well.

share|improve this answer
    
Might that overflow i? – Zachary T Nov 27 at 22:50
    
Yes, it eventually would. Fixed that! – darrylyeo Nov 27 at 22:56
    
Am I mistaken, or do you not need the ,i? – Zachary T Nov 27 at 23:01
    
It's necessary. i++%=4 doesn't work because both ++ and %= perform assignments, and you can only have one assignment operator at a time. – darrylyeo Nov 27 at 23:12
2  
@Xufox The <pre> only ensured a monospaced font was used so that ch units would work. The rules don't mention anything about the font family used. ;) – darrylyeo 2 days ago

Node, 72 70 bytes

f=i=>console.log('\x1BcLoading... '+'|/-\\'[setTimeout(f,250,i=-~i%4),i])

Replace \x1B with the literal escape character to get the correct byte count. Call f() to start the animation. Here's how it looks in the ConEmu terminal emulator on my computer:

enter image description here

share|improve this answer
    
Try using \033c (replace \033 with its actual char representation). It doesn't look as good, but it saves you some bytes. – Mama Fun Roll Nov 27 at 21:43
    
Won't i overflow? – Zachary T Nov 27 at 23:22
6  
@ZacharyT It will after 71 million years, but I can fix that if necessary – ETHproductions Nov 27 at 23:54
1  
"Your program should be able to run indefinitely. For example, if you use a counter for frames, the counter should never cause an error by exceeding the maximum in your language.", yes, it's necessary. – Zachary T Nov 28 at 0:40
    
@ZacharyT OK, fixed. – ETHproductions Nov 28 at 2:46

Windows Batch, 121 114 84 80 79 bytes

Just throwing this out for fun.

for %%b in (/ - \ ^|) do (cls
@echo Loading... %%b
ping 1.1 -n 1 -w 250>nul)
%0

I was not able to assign pipe (|) into the array, so I had to manually add it with another assignment. The delay is done with PING, which might not be accurate.

Output:

enter image description here

Edit:

  • Thanks to Roman Gräf for saving 7 bytes!
  • Thanks to Neil for saving 30 bytes! I have also mangled it a bit more to save bytes on the newlines.
  • Thanks to phyrfox for saving 4 bytes!
  • Thanks to YourDeathIsComing for saving 1 byte!
share|improve this answer
3  
You can remove @echo off and put an @ in front of every set or echo command – Roman Gräf Nov 28 at 9:56
1  
You don't need the array, in (/ - \ ^|) works. Also, %0 is a shorter way to loop than goto. – Neil Nov 28 at 17:32
    
Thanks @Neil! The array notation really helped. Also, I was unsure with how I used %0 here. Is it correct? – user6616962 Nov 29 at 1:54
2  
You should be able to use the IP address "1.1" (-4 bytes), because most platforms will auto-expand that to 1.0.0.1 for you. – phyrfox 2 days ago
1  
You can save 1 byte by removing the space in front of >nul. – YourDeathIsComing yesterday

Kotlin, 67 66 bytes

while(1>0)"|/-\\".map{print("\rLoading... $it");Thread.sleep(250)}

enter image description here

Fairly self explanatory, using \r to clear the line and taking advantage of Kotlin's awesome string interpolation.

EDIT: Saved 1 byte thanks to @mEQ5aNLrK3lqs3kfSa5HbvsTWe0nIu by changing while(true) to while(1>0)

share|improve this answer
1  
You could save one byte by using while(1>0) instead of while(true) (-1) & probably should include the actual function syntax in your answer (fun a(){<code>}, +9). If you wanna be a bit cheaty, you could use store a function as a variable (val a={<code>}, +8). – mEQ5aNLrK3lqs3kfSa5HbvsTWe0nIu Nov 28 at 6:13
2  
@mEQ5aNLrK3lqs3kfSa5HbvsTWe0nIu Is 'full program' mode not acceptable? This can be run as a Kotlin script .kts without class or function definitions. Also, great call with while(1>0)! – Tyler MacDonell Nov 28 at 14:06
2  
But what if, one day, 0 becomes greater than 1???? :P – Flp.Tkc Nov 28 at 15:14
    
Great idea of using Kotlin script. @Flp.Tkc Your comment reminded me of this: codegolf.stackexchange.com/a/101131/62024. Still shuddering that this is possible. – mEQ5aNLrK3lqs3kfSa5HbvsTWe0nIu Nov 28 at 20:00

Pyth - 36 35 bytes

#+"\033cLoading... "@"\|/-"~hZ.d.25

Doesn't work online, obviously.

share|improve this answer
    
Do you have a gif of this in action? Also, is there any counter that could overflow? – Flp.Tkc Nov 28 at 18:01
    
@Flp.Tkc the only counter is Z which is a python integer, which don't overflow. I was trying to make a gif but couldn't get it to work. If you know how to make one, you can run it with the pyth interpreter at github.com/isaacg1/pyth – Maltysen Nov 29 at 2:57
    
If the integer doesn't overflow, then it'll probably grow until filling up all memory, which would make it fail at least after 10⁶⁵⁰⁰⁰⁰⁰⁰⁰ years on most 32-bit systems. Sure, the heat death of the universe will happen first, but still... – jjrv 20 hours ago

C#, 170 133 Bytes

void X(){Console.Write("Loading...  ");for(;;){foreach(var c in "|/-\\"){Console.Write("\b"+c);System.Threading.Thread.Sleep(250);}}}

Big thanks to Roman Gräf and raznagul, who saved me 37 bytes. (Especially raznagul, who pointed out, that my original solution was invalid anyway. I kinda missed out on something there, but it's fixed now and should meet the requirements :)

pretty similar to Pete Arden's existing C# answer but with some improvements

e.g. "for(;;)" instead of "while (true)", char instead of string

I would have commented my suggestions on his answer but I don't actually have enough reputation to do that.

Ungolfed:

static void X()
{
    Console.Write("Loading...  ");
    for (;;)
    {
        foreach (var c in "|/-\\")
        {
            Console.Write("\b" + c);
            System.Threading.Thread.Sleep(250);
        }
    }
}
share|improve this answer
2  
Why don't remove the first Console.Write("\b"); and change the second to Console.Write("\b"+a);? – Roman Gräf Nov 28 at 15:14
    
Defining an action is unnecessary and to long using a loop like foreach(var a in"|/-\\") and add the code you currently have in the action as the body will save you ~20 Bytes. – raznagul Nov 28 at 15:34
    
Also, the task is to create the required output exactly. Which is currently not the case. – raznagul Nov 28 at 16:00
    
It should be the case now, I forgot '|' and the trailing space after "Loading...". – Snowfire Nov 28 at 16:21
    
In your ungolfed version (since it doesn't match the golfed version), you can remove the first Console.Write() and use just one Console.Write($"Loading... {c}\r") instead of the second. – milk Nov 28 at 18:38

Vim, 35 bytes

iLoading... \-/|<Esc>qqdb:sl250m<CR>p@qq@q

The boring version. Here's a non-complying solution that's better:

Vim (1 second sleep), 27 bytes

idbgsp@@<C-U>Loading... \-/|<Esc>@.

Using gs not only is much shorter, but you don't have to hit Enter. That means the macro fits in-line, and I can save bytes by switching to @.. (Since nothing after the recursive call can ever run, I can type whatever I want.)

share|improve this answer

Powershell, 57 56 54 53 58 Bytes

for(;;cls){"Loading... "+"|/-\"[$a=++$a%4];sleep -m 250}

The CLI in powershell will glitch out slightly on some computers, so it doesn't look perfect, but it's as good as I can feasibly get.

Moved $a++ into the for loop to save one byte, (no ;)

Then moved it into the array indexer, for another 2 byte save, thanks to Roman for pointing that out.

Also saved 1 more byte (;) by moving the Clear screen (cls) part into the for loop..

Issue and fix pointed out by TimmyD for the infinite aspect of the question, only +5 Bytes required, changed $a++%4 into ($a=++$a%4) so it will never go above 3.

New updated gif for the (final?) version of this answer.

Loading Gif

for(;;cls){"Loading... "+"|/-\"[$a++%4];sleep -m 250}

for(;;){"Loading... "+"|/-\"[$a++%4];sleep -m 250;cls}

for(;;$a++){"Loading... "+"|/-\"[$a%4];sleep -m 250;cls}

for(;;){$a++;"Loading... "+"|/-\"[$a%4];sleep -m 250;cls}

share|improve this answer
1  
for(;;){"Loading... "+"|/-\"[$a++%4];sleep -m 250;cls} (move the $a++ to the last usage of $a) – Roman Gräf Nov 28 at 14:28
    
always forgetting something - thanks for that! – ConnorLSW Nov 28 at 14:34
    
$a++ will eventually overflow from [int] to [double] and start causing precision issues because the increment is too small. Either that, or it'll eventually overflow [double] and result in Infinity. You can fix that at the cost of three bytes by doing something like for(){"Loading... "+"|/-\"[($a=++$a%4)];sleep -m 250;cls} – TimmyD 2 days ago
1  
I'm not very adept at Powershell, but when I saw the Windows Batch entry, i thought "Could Powershell beat this?". And here it is! – Jakub Jankowski 2 days ago
    
@TimmyD this requires the () wrap to do, so it's actually a 5 byte loss, but neccessary all the same. thanks for pointing that out. – ConnorLSW yesterday

Forth, 72, 73 bytes

EDIT:

  • Added the Gforth-only version, 69 bytes (Thanks @ninjalj !)
  • Added missing whitespace after "Loading..." (Thx @Roman Gräf !), +1 byte
  • Updated to match the rules more precisely (in the same byte count)

Golfed

: L '| '/ '- '\ begin .\" \rLoading... " 3 roll dup emit 250 ms again ; L

Gforth version

The GNU Forth-only version can be brought down to 69 bytes like this:

'| '/ '- '\ [begin] .\" \rLoading... " 3 roll dup emit 250 ms [again]

Screencast

enter image description here

Try it online !

share|improve this answer
1  
Since you are using gforth, if you don't care about portability to other Forth's, you can use [begin] and [again] outside a word definition. – ninjalj yesterday

Dyalog APL, 50 bytes

This only works in the Windows version, as otherwise the ⎕SM window will not show unless ⎕SR is called.

{⎕SM←1 1,⍨⊂⊃⍵⌽'Loading... '∘,¨'|/-\'⋄∇4|⍵+⌈⎕DL÷4}1

Explanation:

  • {...}1: run the function beginning with ⍵=1
  • Loading... '∘,¨'|/-\': generate the four possible outputs
  • ⊂⊃⍵⌽: Rotate the list to put the ⍵th element first, take the first element, and enclose it
  • ⎕SM←1 1,⍨: put the string in the top-left corner of the ⎕SM window.
  • ⎕DL÷4: wait 1/4th of a second
  • 4|⍵+⌈: round up the resulting value (seconds spent waiting, so this is always 1), add it to (incrementing it), and take the mod-4 (to prevent it from eventually overflowing).
  • : run the function again with the new .

Animation

share|improve this answer
    
Somehow I knew someone would submit an answer for this challenge for Dyalog (/APL) :) – YoYoYonnY yesterday

Matlab, 78 75 bytes

a='\|/-';while 1;clc;disp(['Loading... ',a(1)]);a=a([2:4,1]);pause(1/4);end

enter image description here

share|improve this answer

HTML/CSS, 23 + 109 = 132 bytes

Improved upon Neil's answer.

pre{display:flex}a{overflow:hidden;animation:a 1s steps(4)infinite;width:1ch}@keyframes a{to{text-indent:-4ch
<pre>Loading... <a>|/-\

share|improve this answer

MATL, 36 bytes

1 byte removed using @flawr's idea of circularly shifting the string

'\-/|'`Xx1YS'Loading... 'y1)hD.25Y.T

Here is a gif recording from the offline compiler:

enter image description here

Or try it at MATL Online! If it doesn't initially run, refresh the page and press "Run" again.

How it works

'\-/|'           % Push this string
`                % Do...while
  Xx             %   Clear screen
  1YS            %   Circularly shift thr string 1 step to the right
  'Loading... '  %   Push this string
  y              %   Duplicate the string of shifting symbols
  1)             %   Get the first character
  hD             %   Concatenate the two strings and display
  .25Y.          %   Pause for 0.25 seconds
  T              %   Push "true". This is used as loop condition, to it
                 %   generates an infinite loop
                 % End loop implicitly
share|improve this answer
    
@Flp.Tkc I use LICEcap. It exists for Windows and Mac. No Linux unfortunately – Luis Mendo Nov 27 at 22:17
1  
Thanks, installed it! – Flp.Tkc Nov 27 at 22:22

reticular, noncompeting, 40 bytes

:i=@C"Loading... "o"|/-\\".iHo14%w.i1+4,

enter image description here

I forgot to commit a bunch of things, including w. Oh well.

Explanation

:i=@C"Loading... "o"|/-\\".iHo14%w.i1+4,
:i=                                       set `i` to the TOS
   @C                                     clear the screen
     "Loading... "o                       output that string
                   "|/-\\"                push that string
                          .i              get `i`
                            H             get the `i`th character of that string
                             o            and output it
                              14%         push 0.25 (1/4)
                                 w        wait that long
                                  .i      get `i`
                                    1+    increment
                                      4,  mod 4
                                          this wraps around the beginning of the program,
                                          setting i to the said value
share|improve this answer

Mathematica, 74 67 Bytes

ListAnimate["Loading... "<>#&/@{"|","/","-","\\"},AnimationRate->4]

A whopping 7 bytes off thanks to @dahnoak

share|improve this answer
    
ListAnimate["Loading... "<>#&/@Characters@"|/-\\",AnimationRate->4] – dahn oak Nov 28 at 17:25
1  
@dahnoak cheers! I didn't realise ListAnimate was a thing. It's a shame that <> is Flat not Listable otherwise 4 more bytes could be shaved off! – A Simmons Nov 28 at 17:30

><>, 55+4 = 59 bytes

"...gnidaoL"v
l?!voc1. ^:<>
<v<>'\|/-'>^v
^<^<<<8{<<^o<

Must be run passing -t .01 as additional argument to the interpreter, that's the +4 in the byte count.

What this does is putting the four characters to be printed on the stack, printing the top one without removing it and shifting the stack by one position. Then it prints \b (backspace, character x08) and restarts the loop.

Timing is achieved by the argument passed to the interpreter, which forces to wait 0.01 second before executing each instruction. There are 23 instructions between an output and the next one (most of them simply move the instruction pointer to the next cell), so this will wait 0.23 seconds plus the time needed for executing the instructions, which fits without problem in the requested 0.25s with 10% error.

You could try it online, but that interpreter doesn't recognize the backspace character, so the output will be a bit strange there.

share|improve this answer
    
Normally flags like -n are scored as 1 byte, so I think you can score the argument as t, .01 which is 4 bytes. Nice use of the 10% rule btw :) – Flp.Tkc Nov 28 at 22:36
    
@Flp.Tkc Thank you! I wasn't sure of how to count bytes for the argument, I like this way :) – Leo 2 days ago

Bash, 98 69 bytes

while s='\|/-';do
printf "\rLoading... ${s:i=++i%4:1}"
sleep .25
done

Thanks to many people for the many bytes golfed off!

share|improve this answer
    
Also you don't have to escape the backslash if you use single quotes and the arguments for echo -e -n can be combined to echo -en – Evan Chen Nov 28 at 1:58
    
Thanks, I don't usually golf in Bash. – Zachary T Nov 28 at 2:00
    
You can save 2 lines and 13 bytes by replacing the echo line to: echo -en "\rLoading... ${s:i=(i+1)%4:1}" – Ipor Sircer Nov 28 at 2:27
    
Thank you guys so much, 23 bytes!! – Zachary T Nov 28 at 2:32
    
echo -enprintf; make the assignment to s the while condition. – manatwork Nov 28 at 9:28

C#, 187 Bytes

Golfed:

void L(){Console.Write("Loading...");Action<string>l=(a)=>{Console.SetCursorPosition(11,0);System.Threading.Thread.Sleep(250);Console.Write(a);};while(true){l("|");l("/");l("-");l("\\");}

Ungolfed:

public void L()
{
  Console.Write("Loading...");
  Action<string> l = (a) =>
  {
    Console.SetCursorPosition(11, 0);
    System.Threading.Thread.Sleep(250);
    Console.Write(a);
  };
  while (true)
  {
    l("|");
    l("/");
    l("-");
    l("\\");
  }
}

Still waiting for it to load...

enter image description here

share|improve this answer
    
Still waiting for it to display “\”… – manatwork Nov 28 at 13:09
    
@manatwork Oh crap, lazy copy and pasting. Will fix it when I'm back at my desk shortly :) – Pete Arden Nov 28 at 13:16
    
Sorry to see your solution getting longer due to my comment. Can't you use 1>0 instead of true to get it back to 186? – manatwork Nov 28 at 13:37
    
@ErikGolferエリックゴルファー, no idea about C#, but based on the fact the language is a copy of Java and apparently confirmed by Can't cast int to bool, I thought that would not work. (BTW, if that works, maybe using the first call of l() as condition would also work?) – manatwork Nov 28 at 14:00
2  
@manatwork Well, it seems C# is ungolfable. – ErikGolferエリックゴルファー Nov 28 at 14:01

Perl, 71 63 61 bytes

s//\rLoading... |/;select$\,$\,$\,y'-|\/'\/|-'/4while$|=print

Previous version:

$_="\rLoading... |";{$|=print;y#|/\-\\#/\-\\|#;select$\,$\,$\,.25;redo}

Thanx to @primo for 10 bytes.

share|improve this answer
2  
Nice trick to use the select timeout rather than Time::HiRes. You can save a few bytes by using ... while$|=print, and by moving the hyphens in the transliteration to the front and the end. s//\r Loading... |/ also saves a byte over assignment. – primo Nov 28 at 12:41
2  
And also, if you use single quotes for the transliteration delimiter, there's no need to escape the backslash either: y'-\|/'\|/-'. – primo Nov 28 at 12:48
    
It seems you have an extra space before your code. – ErikGolferエリックゴルファー Nov 28 at 13:48
1  
You can save another byte by using a literal \r. – ninjalj Nov 28 at 19:26
1  
Use y'-|\/'\/|-'/4 in place of .25 for 2 more. – primo 2 days ago

Ruby, 66 59 58 57 bytes

I saved 7 bytes when I remembered ruby's loop syntax. -1 byte thanks to manatwork (changed print to $><<)! -1 byte thanks to daniero!

loop{$><<"Loading... #{'|/-\\'[$.=-~$.%4]}\r";sleep 0.25}

Decently self-explanatory. Uses the nice fact that '...' strings don't need to have double-escapes I had to rework the string, so now the \ is at the end and must be escaped.

share|improve this answer
    
print$><< – manatwork Nov 28 at 9:30
    
@manatwork Oh, cool! – Conor O'Brien Nov 28 at 12:09
    
You can use $. instead of initializing i, as explained here. Saves at least two bytes – daniero yesterday
    
@daniero thanks! – Conor O'Brien yesterday

NASM x86_64 - 349 283 bytes

This should be run 64 bit linux systems

built using:

nasm loading_golfed.asm -felf64 && ld loading_golfed.o

%use altreg
global _start
section .data
o:db"Loading...  "
s:db"|/-\\"
b:db`\bx`
q:dq 0,250000000
_start:mov r0,1
mov r7,1
mov r6,o
mov r2,12
syscall
mov r2,2
l:mov r7,1
mov al,[s+r8]
mov [b+1],al
mov r0,1
mov r6,b
syscall
mov r0,35
lea r7,[q]
mov r6,0
syscall
inc r8
and r8,3
jmp l

animation:

saved 65 bytes - thanks user254948

enter image description here

share|improve this answer
    
I count 349 bytes, unless there's a trailing newline/space – Flp.Tkc 2 days ago
    
^Flp. Tkc Thanks, there was a line with a space at the end – Samuel 2 days ago
    
@Samuel are lines 13-17 needed? It seems to work pretty much fine without those lines. As far as I can tell (Not that great in assembly I'm afraid) you print the Loading...., then the | character, then remove that character, then enter a loop where you repeat printing the | for the first time. – user254948 17 hours ago
    
@Samuel in addition xor r8,r8 -> mov r8,0 (saves 1 character), some MOV's have an extra space (mov r7, 1 -> mov r7,1). further more the instructions cmp r8,4, jl l, xor r8,r8, can be replaced by AND r8,3 (saving 15 characters). You should be down to 285 bytes then instead of 349! (in combination with the lines mentioned above) – user254948 16 hours ago

Python 2, 81 79 78 bytes

import time
i=1
while 1:print'\rLoading... '+'\|/-'[i%4],;i+=1;time.sleep(.25)

Quite a simple solution that sleeps using time.

I use \r (A carriage return) to go back to the start of the line and then print the message overwriting the line.

I start with i=1 to avoid double escaping the \ (It is '\|/-' instead of '|/-\\').

In the past, I had used -~i to mean i + 1 to avoid parentheses. (Thanks to @Flp.Tkc for these -2 bytes!) (It was i=(i+1)%4 vs. i=-~i%4)

Now, I am just letting the counter rise forever, as technically Python ints can't overflow. Thanks to @Zachary T for pointing that out and saving a byte!
It only stops on a machine because the machine runs out of memory, but this takes 9.7 generations with 4GB of memory for that one int.

Here's a gif of it working on Windows:

Loading

I tested it on a Linux VM too. I couldn't test it on a Mac.

share|improve this answer
1  
If I remember correctly, you can use i=-~i%4 to save the bytes for the parens :) – Flp.Tkc Nov 27 at 21:48
2  
Won't replacing [i],;i=-~i%4 with [i%4],;i+=1 save a byte since it doesn't exceed the max for Python, only the maximum memory? – Zachary T Nov 27 at 22:03
7  
I should downvote you for logging in as Administrator... – Neil Nov 27 at 22:06
4  
@Neil To be totally honest, I just put the Python file in Administrator and ran it from there because the other account names are real names (Personal PC). – Artyer Nov 27 at 22:07
2  
I'd allow @ZacharyT 's suggestion as technically Python integers can be infinitely large, as long as the computer has memory to hold them – Flp.Tkc Nov 27 at 22:11

PHP, 58 bytes

for(;;usleep(25e4))echo"\rLoading... ","\\|/-"[$i=++$i%4];

uses carriage return = overwrites the whole line. Run with -r.

share|improve this answer
    
@user59178: The assignment is needed to avoid integer overflow. Can you tell me how to run code with single and double quotes with -r? – Titus Nov 28 at 14:29
    
Those are both excellent points, I probably should have actually tried running it, rather than just looking at the code.:-) – user59178 Nov 28 at 15:36

Pascal, 116 114 107 105 bytes

where is my head.. Thanks to @manatwork for shaving few bytes!

uses crt;var c:char;begin while 1=1do for c in'|/-\'do begin Write(#13'Loading... ',c);Delay(250)end;end.

Ungolfed:

uses
  crt;    // CRT unit has Delay function

var
  c: char;

begin
  while 1=1 do
    for c in '|/-\' do
    begin
      Write(#13'Loading... ', c);
      Delay(250)
    end;
end.
share|improve this answer
1  
True1=1 and that way you can remove the following space too. – manatwork Nov 28 at 10:26
1  
Better use a single output statement rewriting the entire line: Write(#13'Loading... ',c);. (BTW, no need for , between character and string literals.) – manatwork Nov 28 at 10:32
    
@manatwork - thanks, that makes more sense – hdrz Nov 28 at 10:34
    
Oh, and no need for the ; in front of 1st end. – manatwork Nov 28 at 10:38
    
Got it. have to eat something.... – hdrz Nov 28 at 10:57

Haskell (GHC), 103 91 bytes

import GHC.Conc
mapM((>>threadDelay 250000).putStr)$("\rLoading... "++).pure<$>cycle"|/-\\"

Thanks @nimi for saving 12 bytes!

share|improve this answer
    
No need for a full program. mapM((threadDelay 250000>>).putStr)$("\rLoading... "++).pure<$>cycle"|/-\\". – nimi Nov 28 at 13:11
    
Two bytes might be saved by using the 10% tolerance and replacing 250000 and the space before it with (4^9). – Christian Sievers Nov 29 at 3:45

Perl 6, 72 61 bytes

Supply.interval(1/4).tap: {print "\rLoading... ",<| / - \ >[$/++];$/%=4}
loop {print "\rLoading... ",<| / - \ >[$/++];$/%=4;sleep 1/4}
share|improve this answer

C (on UNIX-like systems) 88 bytes

main(_){for(;;){_%=4;printf("\rLoading... %c","\\-/|"[_++]);fflush(0);usleep(250000);}}

It starts with the wrong character, but I think it looks nicer. You can easily change the character order by modifying the "\-/|" string.

share|improve this answer
    
Could be golfed further by moving statements into for, e.g: ain(_){for(;printf("\rLoading... %c","\\-/|"[_%4]);usleep(250000))_++,fflush(0);}, then could be golfed further assuming wraparound for integer overflow: main(_){for(;printf("\rLoading... %c","\\-/|"[_++%4]);usleep(250000))fflush(0);} – ninjalj Nov 29 at 0:20

Wonder, 50 bytes

f\@(ol ++"�Loading... ":#0"\|/-";%%25e4;f +1#0);f0

Replace with the actual carriage return \r.

Explanation

f\@(...);f0: Infinitely recursive function f.

:#0"\|/-": Modular indexing using the function argument and the string "\|/-".

ol ++"�Loading... ": Return cursor to beginning of line, concatenate previous result to Loading..., and output.

%%25e4: Sleep for 250000 nanoseconds.

f +1#0: Call f on the argument incremented.

share|improve this answer
    
Would this reach maximum recursion depth and crash? – Flp.Tkc Nov 29 at 6:51
    
I don't think so, although I haven't tried running it for very long. Sort of weird, given that I should know how the interpreter works. – Mama Fun Roll Nov 29 at 6:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.