[Question]
  [
Your challenge is to make an infinite loading screen, that looks like this:
[![enter image description here](https://i.stack.imgur.com/d0hvj.gif)](https://i.stack.imgur.com/d0hvj.gif)
---
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), 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!
  
[Answer]
## HTML/CSS, ~~183~~ ~~180~~ ~~163~~ ~~161~~ ~~160~~ ~~147~~ 143 bytes
```
a{display:inline-flex;overflow:hidden;width:1ch}c{animation:c 1s steps(4)infinite}@keyframes c{to{margin:0-4ch
```
```
<pre>Loading... <a><c>|/-\</pre>
```
Edit: Saved 3 bytes thanks to @betseg. Saved 17 bytes thanks to @manatwork. Saved 1 byte thanks to @Daniel. Saved 13 bytes thanks to @Ismael Miguel. Saved 4 bytes thanks to @Fez Vrasta.
[Answer]
# 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](https://i.stack.imgur.com/jp1Kn.gif)](https://i.stack.imgur.com/jp1Kn.gif)
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
```
[Answer]
# 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](https://codegolf.stackexchange.com/a/101315/47097) as well.**
[Answer]
# Windows Batch, ~~121~~ ~~114~~ ~~84~~ ~~80~~ ~~79~~ 78 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](http://www.robvanderwoude.com/wait.php#PING).
Output:
[![enter image description here](https://i.stack.imgur.com/93hDo.gif)](https://i.stack.imgur.com/93hDo.gif)
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 2 bytes!
[Answer]
# 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](https://i.stack.imgur.com/GlZ0G.gif)](https://i.stack.imgur.com/GlZ0G.gif)
[Answer]
# Pyth, 31 bytes
```
Wm,p+"\rLoading... "d.d.25"|/-\
```
Interpreter [here](https://github.com/isaacg1/pyth).
![Loading GIF](https://i.stack.imgur.com/U5hCD.gif)
## Explanation
```
Wm,p+"\rLoading... "d.d.25"|/-\
    +"\rLoading... "d              Concatenate the string "\rLoading... " and the variable d
   p                               Print the result without a newline
                     .d.25         Sleep for 0.25 seconds
  ,                                Form a two-element list with the results of the two statements above. This is only needed to execute both statements in a single lambda function.
 m                        "|/-\    Map the above statement over the characters in the string "|/-\", setting the variable d to the character for each iteration
W                                  While the result of the map statement is true, do nothing
```
[Answer]
## Kotlin, 67 66 bytes
```
while(1>0)"|/-\\".map{print("\rLoading... $it");Thread.sleep(250)}
```
[![enter image description here](https://i.stack.imgur.com/FdSsE.gif)](https://i.stack.imgur.com/FdSsE.gif)
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)`
[Answer]
# 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.)
[Answer]
## Powershell (v4), ~~57~~ ~~56~~ ~~54~~ ~~53~~ ~~58~~ 57 Bytes
Back at the Bytecount I started with!
`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.
Saved another byte by leaving the for loop totally blank, thanks to 'whatever' for pointing out that this is actually possible in Powershell Version 4!
New updated gif for the ~~(final?)~~ version of this answer.
[![Loading Gif](https://i.stack.imgur.com/3qIoC.gif)](https://i.stack.imgur.com/3qIoC.gif)
~~`for(;;cls){"Loading... "+"|/-\"[($a=++$a%4)];sleep -m 250}`~~
~~`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}`~~
[Answer]
# Pyth - ~~36~~ 35 bytes
```
#+"\033cLoading... "@"\|/-"~hZ.d.25
```
Doesn't work online, obviously.
[Answer]
# 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](https://i.stack.imgur.com/PzMj9.gif)](https://i.stack.imgur.com/PzMj9.gif)
[Answer]
# HTML/CSS, 23 + 109 = 132 bytes
Improved upon [Neil's answer](https://codegolf.stackexchange.com/a/101298/47097).
```
pre{display:flex}a{overflow:hidden;animation:a 1s steps(4)infinite;width:1ch}@keyframes a{to{text-indent:-4ch
```
```
<pre>Loading... <a>|/-\
```
[Answer]
## Mathematica, ~~74~~ 67 Bytes
```
ListAnimate["Loading... "<>#&/@{"|","/","-","\\"},AnimationRate->4]
```
A whopping 7 bytes off thanks to @dahnoak
[Answer]
## 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);
        }
    }
}
```
[Answer]
# 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](https://i.stack.imgur.com/80Ige.gif)](https://i.stack.imgur.com/80Ige.gif)
[**Try it online !**](https://goo.gl/3zmdIy)
[Answer]
# Python 2, ~~81~~ ~~79~~ ~~78~~ 77 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](https://codegolf.stackexchange.com/users/60919) 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 `int`s can't overflow. Thanks to [@Zachary T](https://codegolf.stackexchange.com/users/55550) 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](http://www.wolframalpha.com/input/?i=(4GiB+%2F+(4+bit+Hz)) "Wolfram|Alpha link") with 4GB of memory for that one `int`.
Thanks to [@Kade](https://codegolf.stackexchange.com/users/38417) for the -1 byte where `print a,b` prints `a` and `b` space seperated, so I don't need my own space.
Here's a gif of it working on Windows:
[![Loading](https://i.stack.imgur.com/LCSYi.gif "Loading...")](https://i.stack.imgur.com/LCSYi.gif "Loading...")
I tested it on a Linux VM too. I couldn't test it on a Mac.
[Answer]
# 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](https://i.stack.imgur.com/HS1WQ.gif)](https://i.stack.imgur.com/HS1WQ.gif)
[Answer]
# 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](https://i.stack.imgur.com/FB85j.gif)](https://i.stack.imgur.com/FB85j.gif)
[Answer]
## MS-DOS .COM file, 56 bytes
Here the file content in hexadecimal:
```
b4 09 ba 2c 01 cd 21 b2 2f e8 11 00 b2 2d e8 0c
00 b2 5c e8 07 00 b2 7c e8 02 00 eb ea b4 02 cd
21 b2 08 cd 21 b9 05 00 f4 e2 fd c3 4c 6f 61 64
69 6e 67 2e 2e 2e 20 24
```
The matching assembler code looks like this:
```
    mov ah, 9      ; Print "Loading... "
    mov dx, text
    int 21h
theloop:
    mov dl, '/'    ; Call "chrout" for "/", "-", "\" and "|"
    call chrout
    mov dl, '-'
    call chrout
    mov dl, '\'
    call chrout
    mov dl, '|'
    call chrout
    jmp theloop    ; Endless loop
chrout:            ; Sub-Function "chrout"
    mov ah, 2      ; Output the character
    int 21h
    mov dl, 8      ; Output backspace
    int 21h
    mov cx,5       ; Call "HLT" 5 times
timeloop:
    hlt            ; Normally HLT will wait ~55 milliseconds
                   ; (Assuming no keyboard key is pressed)
    loop timeloop
    ret            ; End of the function
text:
    ASCII "Loading... ",'$'
```
[Answer]
# Snap!, 8 blocks
![8 blocks of Snap!](https://i.stack.imgur.com/ytwqZ.png)
This was one of the very first algorithms I ever puzzled out on an Apple ][e
[Answer]
# [MATL](https://github.com/lmendo/MATL), 36 bytes
*1 byte removed using [@flawr's idea](https://codegolf.stackexchange.com/a/101293/36398) of circularly shifting the string*
```
'\-/|'`Xx1YS'Loading... 'y1)hD.25Y.T
```
Here is a gif recording from the offline compiler:
[![enter image description here](https://i.stack.imgur.com/Xf5LC.gif)](https://i.stack.imgur.com/Xf5LC.gif)
Or try it at [MATL Online!](https://matl.io/?code=%27%5C-%2F%7C%27%60Xx1YS%27Loading...+%27y1%29hD.25Y.T&inputs=&version=19.5.1)
### 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
```
[Answer]
# 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!
[Answer]
# [Perl 6](https://perl6.org), ~~72~~ 61 bytes
```
Supply.interval(1/4).tap: {print "\rLoading... ",<| / - \ >[$/++];$/%=4}
```
```
loop {print "\rLoading... ",<| / - \ >[$/++];$/%=4;sleep 1/4}
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 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](http://fish.tryitonline.net/#code=Ii4uLmduaWRhb0widgpsPyF2b2MxLiBeOjw-Cjx2PD4nXHwvLSc-XnYKXjxePDw8OHs8PF5vPA&input=&args=LXQgLjAx), but that interpreter doesn't recognize the backspace character, so the output will be a bit strange there.
[Answer]
# 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](https://i.stack.imgur.com/GErli.gif)](https://i.stack.imgur.com/GErli.gif)
[Answer]
# reticular, 40 bytes
```
:i=@C"Loading... "o"|/-\\".iHo14%w.i1+4,
```
[![enter image description here](https://i.stack.imgur.com/rL2rm.gif)](https://i.stack.imgur.com/rL2rm.gif)
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
   
```
[Answer]
## R, 85 89 bytes
```
repeat{if(T>4)T=1;cat("\fLoading...",c("|","/","-","\\")[T],sep="");T=T+1;Sys.sleep(.25)}
```
Edit: Fixed the answer such that `T` wont overflow by resetting the counter if greater than `4`.
The only interesting aspect about this answer is the use of R's `TRUTHY` builtin `T`. It is effectively a predefined variable set to `1/TRUE` which means we don't have to initialize the counter but can start incrementing `T`.
[Answer]
# Haskell (GHC), ~~103~~ 91 bytes
```
import GHC.Conc
mapM((>>threadDelay 250000).putStr)$("\rLoading... "++).pure<$>cycle"|/-\\"
```
Thanks @nimi for saving 12 bytes!
[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.
[Answer]
# 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.
]