TransWikia.com

Loading... Forever

Code Golf Asked by FlipTack on January 20, 2021

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!

92 Answers

Groovy, 60 bytes 59 bytes, 61 bytes

print'Loading...';for(;;)'|/-\'.any{print"$itb";sleep 250}

(modified to work with later versions of groovy, removed ascii cast)

Answered by Matias Bjarland on January 20, 2021

Yabasic, 83 bytes

An anonymous function that takes no input and outputs to the console in graphics mode. Does not function with TIO.

Clear Screen
?"Loading..."
Do
?@(1,11)Mid$("|/-\",i+1,1)
Wait.25
i=Mod(i+1,4)
Loop

Answered by Taylor Scott on January 20, 2021

><> with -t.03 flag, 33 bytes

'o!vooooo|-/ ...gnidaoL
{[4<o8o:

Try it online!

The only part of the specification this doesn't implement is that the first frame should be printed as soon as the program is run which seems rather strict and unobservable. The first frame here take 1.08 seconds to print, and every frame after that takes 0.24 seconds.

Answered by Jo King on January 20, 2021

Japt, 38 bytes

@Oq Oo`LoÃHg... `+"|/-\"gW°%4)1
a#úiU

Try it online!

How it works

@Oq Oo`LoÃHg... `+"|/-\"gW°%4)1
a#úiU

@               Declare a function...
 Oq               that clears the screen,
 Oo"Loading... "  prints this string,
 +"|/-\"gW++%4   plus the spinner char (using a variable W),
 )1               and finally returns 1
                and implicitly store this function to U.

a       Call U once (return 1 is needed for this)
 #úiU   and call U every 250 milliseconds.

By the nature of Japt syntax, it's impossible to call U() directly (well, it's possible using JS directive $...$ but it's too long after all.) So we use U.a() method that calls U with numbers from 0 to infinity until U returns true. If you omit )1 at the end of the first line and try running it, your browser will hang.

Without the initial U() call, the output window will show the implicit output (seemingly random integer value) before first showing the Loading... text.

Finally, a#úiU actually translates to U.a(250 .i(U)), which registers the 250ms loop first and then passes the return value (which happens to be undefined) to U.a (which accepts optional function argument, but seems to do nothing special with undefined).

Answered by Bubbler on January 20, 2021

C++ (224)

This certainly isn't the shortest code to do this. I like doing coding challenges, so I'm posting it anyway.

#include <iostream>
#include <string>
#include <thread>
using namespace std;int main(){string s = "|/-\";int i=0;cout<<"Loading... ";while(1){cout<<s[i];this_thread::sleep_for(chrono::milliseconds(99));cout<<"b";i=++i%4;}}

Answered by Colin Robertson on January 20, 2021

ES8 + HTML, 68 bytes

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

Answered by copyreplace on January 20, 2021

PHP, 56 bytes

while(!usleep(25e4))echo"rLoading... ",'|/-'[@$i++%4];

Answered by kip on January 20, 2021

T-SQL, 121 bytes

DECLARE @ CHAR W:SET @=IIF(@='/','-',IIF(@='-','',IIF(@='','|','/')))PRINT'Loading... '+@ WAITFOR DELAY'0:0:0.25'GOTO W

Answered by WORNG ALL on January 20, 2021

Java 7, 121 118 bytes

void f()throws Exception{for(int k=0;;k++){System.out.print("rLoading... 
"+"|/-\".charAt(k%=4));Thread.sleep(250);}}

Gif animation:

enter image description here

Answered by Twometer on January 20, 2021

Charcoal, 34 bytes

Loading... A⁰αHW²⁵⁰¦¹«A⁺¹ααP§|/-α

Try it online! Refresh command has changed since so it is different on TIO. Link to verbose code for explanation.

Answered by ASCII-only on January 20, 2021

C function, 73 bytes

i;f(){for(;write(1,"rLoading... -b\b|b/",13+i%8);i++)usleep(1<<17);}

Tested on SystemResque-Cd 4.9.6 in this program:

#include <stdio.h>
#include <unistd.h>

/*
i;
f(){
        for(
            ;
            write(1, "rLoading... -b\b|b/", 13+i%8);
            i++
        ){
                usleep(1<<17);
        }
}
*/
i;f(){for(;write(1,"rLoading... -b\b|b/",13+i%8);i++)usleep(1<<17);}

int main(){
        f();
        return 0;
}

compiled with gcc 4.9.4

Answered by epimatech on January 20, 2021

Rust, 117 Bytes

print!("Loading... ");fn f(){let a="\|/-";for n in 0 .. 4{std::thread::sleep_ms(250);print!("x08{}",a[n]);}f();}f;

Fixed some compile errors. Nowhere near a compiler right now so bear with me.

Answered by Chad Baxter on January 20, 2021

shortC, 59 bytes

i;f(){O;;i=4)Wi--)dR2,"rLoading... %c","|\-/"[i]),U250000

Answered by MD XF on January 20, 2021

C, 92 89 82 bytes

i;f(){for(;;i=4)while(i--)dprintf(2,"rLoading... %c","|\-/"[i]),usleep(250000);}

Answered by MD XF on January 20, 2021

C++, 109 Bytes

There should be a lot to improve, it's my first golf code. Feedback is greatly appreciated :)

#import<stdio.h>
#import<unistd.h>
int b;main(){for(;;usleep(2500))printf("rLoading...%c","-\|/"[++b%=4]);}

Answered by Clémox on January 20, 2021

JavaScript (ES6) + HTML, 77 74 bytes

f=c=>setTimeout(f,250,-~c%4,o.value="Loading... "+"|/-\"[~~c])
<input id=o

Try It

(f=c=>setTimeout(f,250,-~c%4,o.value="Loading... "+"|/-\"[~~c]))()
<input id=o>

Answered by Shaggy on January 20, 2021

PKod , 48 bytes ~ Non-Competing

Possibly the only way I can do this, as PKod only has one write-able variable lL=oo=ao=do=io=no=go=.ooo =|oyw=/oyw=-oyw=oywl<

Explanation: l - Clear screen and since its the first char, allow printing no operation (NOP) chars
             L - NOP, thus print "L"
             =oo=ao=do=io=no=go=.ooo - Set as certain chars and print them.
             (space) - Another NOP, thus print a space
             =|oyw - Set char as "|", print it, then wait a quarter of a second and remove it
             =/oyw=-oyw=oywl - Same as above, with different symbols to match the challenge
             < - Go back to the start

"Gif" (more like mp4): https://i.gyazo.com/577dd164313a6b2e5dbf40249efb435d.mp4

You can see quote marks around the code in the console, thats because cmd tries to do stuff with my "<" and would return an error. It's just to nicely pass the code to the interpeter without cmd interfering.

Answered by P. Ktinos on January 20, 2021

Commodore 64 (or VIC-20), 123 Bytes

0 A$="/|-":A=1:FORI=0TO1STEP0:PRINT"{home}LOADING..."MID$(A$,A,1):A=A+1:GOSUB2:ON-(A>4)GOTO0
1 NEXT
2 FORX=0TO99:NEXT:RETURN

Using print 38911-(fre(0)-65536*(fre(0)<0)) tells me that I have consumed 123 bytes of the computers memory (on the C64); this will probably work on other variants of Commodore BASIC, such as the BASIC 7; you will need to use BASIC keyword abbreviations to enter it on a real C64 or VIC-20.

The BASIC listing from an emulator screen grab

In order to make it infinite*, you will need to disable the RUN/STOP key with a POKE, I think it's POKE 808,234 - that will mean you can't break into the BASIC listing without an Action Replay or a soft reset or something. The time delay can be altered in line 2 - increase the FOR X counter as required.

Answered by Shaun Bebbers on January 20, 2021

SmileBASIC, 57 bytes

@L CLS?"Loading... "+"|/-"[I]:I=(I+1)MOD 4 WAIT 15 GOTO@L

Ungolfed:

@L                       'loop start
CLS                      'clear console
?"Loading... "+"|/-"[I] 'construct our output and print
I=(I+1)MOD 4             'inc counter, MOD to prevent overflow
GOTO @L                  'loop

Answered by snail_ on January 20, 2021

C#, 183 180 178 170 161 140 bytes

I know a C# solution has already been posted, but this one is a fully functional console program (including usings) in less bytes!

Golfed

class P{static void Main(){for(int i=0;;){System.Console.Write("rLoading... "+@"|/-"[i=i++==3?0:i]);System.Threading.Thread.Sleep(250);}}}

Ungolfed

class P
{
    static void Main()
    {
        for (int i = 0; ;)
        {
            System.Console.Write("Loading... "+@"|/-"[i = i++ == 3 ? 0 : i]);
            System.Threading.Thread.Sleep(250);
        }
    }
}

Yes, I'm probably very late, but I had to post it..!

EDIT: I figured someone else posted a 109 byte C# solution, oh well
EDIT 2: Thanks to the poster of the 109 byte C# solution, I managed to lose 3 more bytes by removing i<4 from my for loop, thanks!
EDIT 3: Removed C# 6 string interpolation and used good old + instead to save 2 more bytes.
EDIT 4: Not declaring a var for the animation characters anymore, instead I added them directly into the Write() method, saving another 8 bytes
EDIT 5: Removed the parameter string[]s from the Main method to save 9 bytes!
EDIT 6: Used carriage return instead of System.Console.Clear(), removed a using and moved the incrementing of i + the ternary inside of System.Console.Write(), all thanks to @CSharpie! (all this saved 21 bytes)

Answered by Metoniem on January 20, 2021

Bash, 100 bytes

while [ 1 ]; do for i in `echo '|/-' | grep -o .`; do printf $'rLoading...'$i;sleep 0.25;done;done

This is not nicely golfed, so please tell me where I can improve here.


This does work, and has been tested on a Raspbian Raspberry Pi, an Amazon server, and an Ubuntu machine. This would not work on a Solaris machine because the sleep command on those systems cannot take inputs less than 1.

Answered by ckjbgames on January 20, 2021

SmileBASIC, 51 46 bytes

CLS?"Loading... ";"|-/"[3AND MAINCNT/15]EXEC.

Answered by 12Me21 on January 20, 2021

tcl, 79

while 1 {lmap c {| / - \} {puts -nonewline stderr rLoading... $c;after 250}}

assuming I can write to stderr instead of stdout

Answered by sergiol on January 20, 2021

tcl, 83

while 1 {lmap c {| / - \} {puts -nonewline rLoading...$c;flush stdout;after 250}}

Can be seen running on: https://goo.gl/BJmxV0

Answered by sergiol on January 20, 2021

TI-Basic (CE/CSE only), 57 bytes

:ClrHome
:Disp "LOADING...
:For(A,1,5
:A-4(A=5→A
:Output(1,12,sub("+/-*",A,1
:Pause .25
:End

Notes:

  • Many commands in TI-Basic are 1-2 byte tokens, which may make it appear to be a byte miscount.

  • Due to TI-Basic's very limited character set, the following characters have been replaced: | with +*.

  • This will only run correctly on the newest version of a TI-84+ CE or CSE.

Answered by Julian Lachniet on January 20, 2021

awk, 46 bytes

In awk, with some help from ANSI codes and the rotor comes piped in:

{while(i=1+i%4)print"Loading... "$i"33[1A"}

Try it:

$ echo |/-\|awk -F '' '{while(i=1+i%4)print"Loading... "$i"33[1A"}'
Loading...[|/-]

One byte comes off if NF is replaced with 4. I didn't wait to see if i iterates to oblivion.

Answered by James Brown on January 20, 2021

Noodel, noncompeting 24 25 bytes

Cannot compete because Noodel was born after the challenge.

”|gAĖọẸ.?a5‘|/-⁺ʂḷạÇḍ/4

Had to add a byte because messed up the compression algorithm:(

“Loading...¤‘|/-⁺ʂḷạÇḍ/4

Try it:)

How it works

“Loading...¤              # Creates a string that is "Loading...¤" that is placed into the pipe.
            ‘|/-         # Creates a character array ["|", "/", "-", ""]
                 ⁺ʂ       # Adds two items in the pipe which will add the string to each character in the array. The 'ʂ' forces it to prepend rather than append.
                   ḷ      # Unconditionally Loop everything up until a new line or end of program.
                    ạ     # Basic animation, iterates through an object moving to the next index every call on that object and returns what is at that index.
                     Ç    # Clears the screen then prints what is in the front of the pipe and dumps what was displayed.
                      ḍ/4 # Delays for the specified amount of time (/4 => 1/4 => 0.25s)

Stepping The Pipe

-->
--> "Loading...¤"
--> ["|", "/", "-", ""], "Loading...¤"
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]
Loop ----------------------------------------------------------------------------------------
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]
--> "Loading...¤|", ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:0>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:0>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:0>
Loop ----------------------------------------------------------------------------------------
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:0>
--> "Loading...¤/", ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:1>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:1>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:1>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:1>
Loop ----------------------------------------------------------------------------------------
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:1>
--> "Loading...¤-", ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:2>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:2>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:2>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:2>
Loop ----------------------------------------------------------------------------------------
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:2>
--> "Loading...¤", ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:3>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:3>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:3>
--> ["Loading...¤|", "Loading...¤/", "Loading...¤-", "Loading...¤"]<frame:3>

There currently is not a version of Noodel that supports the syntax used in this answer. Here is a script that is supported:

23 bytes

Loading...¤”Ƈḟḋḣ⁺sḷạÇḍq

<div id="noodel" code="Loading...¤”Ƈḟḋḣ⁺sḷạÇḍq" input="" cols="12" rows="2"></div>

<script src="https://tkellehe.github.io/noodel/release/noodel-1.1.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>

Answered by tkellehe on January 20, 2021

Python 3, 94 bytes

Okay. First answer. EDIT: SAVED 8 BYTES EDIT 2: SAVED 1 BYTE EDIT 3: SAVED 11 BYTES EDIT 4: SAVED 3 BYTES EDIT: SAVED 5 BYTES EDIT: SAVED 2 BYTES

import time
while 1:
 for f in 0,1,2,3:print("Loading...","|/-\"[f],end="r");time.sleep(.25)

Ungolfed:

import time
while True: # Loop forever
    for f in [0, 1, 2, 3]: # Loop four times
    print("Loading...", "|/-\"[f], end="r") # Print Loading... then the current frame
        time.sleep(0.25) # Wait 0.25 seconds

Answered by python-b5 on January 20, 2021

PowerShell, 116 77 69 67 bytes

for(){[char[]]'|/-'|%{write-host -n `rLoading... $_;sleep -m 250}}

cleaner than cls?

Answered by Dan on January 20, 2021

Turing machine simulator, 189 bytes

0 * L r 1
1 * o r 2
2 * a r 3
3 * d r 4
4 * i r 5
5 * n r 6
6 * g r 7
7 * . r 8
8 * . r 9
9 * . r A
A * * r B
B -  * C
B / - * C
B | / * C
B * | * C
C * * * D
D * * * E
E * * * F
F * * * B

Do not run on full speed, or it will not wait for ~0.25 s1.

1Dunno if actually within 10% of 0.25 s. Last 4 lines do the waiting job approximately.

Answered by Erik the Outgolfer on January 20, 2021

Batch, 88 81 77 bytes

:1
@FOR %%G IN (/,-,,^|) DO @(echo Loading...%%G
timeout/t 1 >a
cls)
@goto 1

GIF

(My first answer on Code Golf...)

Answered by undo on January 20, 2021

F# (interactive), 81 bytes

async{while 1>0 do for c in"|/-\"do printf"rLoading... %O"c;do!Async.Sleep 250}

In order to run it in F# interactive, you have to pass it to Async.Start or Async.RunSynchronously.

For reference, a little longer non-async version:

while 1>0 do for c in"|/-\"do printf"rLoading... %O"c;System.Threading.Thread.Sleep 250

and a slightly outdated gif :)

enter image description here

Answered by pmbanka on January 20, 2021

C#, 168 136 123 109 Bytes

Golfed:

void S(){for(int a=0;;a++){Console.Write("rLoading... "+"|/-\"[a%=4]);System.Threading.Thread.Sleep(250);}}

Ungolfed:

void S()
{
    for(int a = 0; ; a++)
    {
        Console.Write("rLoading... " + "|/-\"[a%=4]);
        System.Threading.Thread.Sleep(250);
    }
}

See it working here:

enter image description here

Edit: Simplified the array.

Edit2: For is way better for this.

Answered by GonacFaria on January 20, 2021

Scala, 86 bytes

def t(i:Int=0):Any={print("b"*12+"Loading... "+"|/-\"(i));Thread sleep 250;t(i+1&3)}

Explanation:

def t(i:Int=0):Any={ //define a method t
  print(               //print...
    "b"*12+             //a backspace character repeated 12 times to delete everything
    "Loading... "+       //the string "Loading... 
    "|/-\"(i)           //and the i-th char of the char in question
  );
  Thread sleep 250;    //sleep 250ms
  t(i+1&3)             //call t with i incremented by one, but capped at 3
}

Like most other answers, it looks pretty standard console-like.

Answered by corvus_192 on January 20, 2021

Ruby, 57 bytes

Same length as Conor O'Brien's answer, but a different approach:

%w(| / - \).cycle{|c|$><<"Loading... #{c}r";sleep 0.25}

Answered by daniero on January 20, 2021

C# - 111 bytes

Just added some "creative [ac]counting" to existing C# answers.

void G(){for(var i=0;;i=i%4+1){Console.Write("rLoading... "+"|/-\|"[i]);System.Threading.Thread.Sleep(250);}}

Human readable version.

void G()
{
    for (var i = 0; ; i = i % 4 + 1)
    {
        Console.Write("rLoading... " + "|/-\|"[i]);
        System.Threading.Thread.Sleep(250);
    }
}

Answered by Luc on January 20, 2021

Befunge 98, 61 bytes

Requires the HRTI (High Resolution Timers) fingerprint.

"ITRH"4(v
"g2:%4+1<,M',*93,aj*-d0`T**::?'M,kb"Loading...
|/-

Waits 250047 (63^3) microseconds using a busy loop, using the M (mark) and T (returns the number of microseconds since the last mark) instructions from the "HRTI" fingerprint.

After each line, it outputs "neM", to force a flush, and reposition the cursor.


Version for terminals using 8-bit encodings with proper support for C1 control codes (59 bytes):

"ITRH"4(v
"g2:%4+1<,+f~',aj*-d0`T**::?'M,kb"Loading...
|/-

This version outputs "nx8d" after each line. "x8d" is the 8-bit equivalent of 7-bit "eM", and is supported by e.g: xterm +u8 (xterm not in UTF-8 mode).

Answered by ninjalj on January 20, 2021

Windows Batch, 109 bytes

This is just another solution in Windows Batch

@echo off
call:s ^|
call:s /
call:s -
call:s 
%0
:s
cls
echo Loading... %1
ping 1.1 -n 1 -w 250>nul
goto:eof

I'm not quite shure what's wrong with the pipesymbol.

Answered by YourDeathIsComing on January 20, 2021

Rust, 196 bytes

use std::*;
use std::io::Write;
fn main(){let mut i=0;loop{print!("Loading... {}",['|','/','-','\'][i]);io::stdout().flush();thread::sleep(time::Duration::from_millis(250));i=(i+1)%4;print!("r")}}

Ungolfed with explanation:

// We have to use the std library before we can use the io, time, and thread modules
use std::*;
// We also have to have the std::io::Write trait in scope before we can use the functions it defines (like flush)
use std::io::Write;
// The main function
fn main() {
  // Our counter. It has to be declared mutable so that we can change it
  let mut i = 0;
  // loop creates an infinite loop 
  loop {
    // print the loading text with the current spinner char
    // ['|','/','-',''][i] must be used instead of "/-\"[i] because Rust's strs and Strings don't allow indexing. :(
    print!("Loading... {}", ['|','/','-',''][i]);
    // Flush stdout. Without this nothing will be displayed on the screen
    io::stdout().flush();
    // Sleep for 250 ms (0.25 secs)
    thread::sleep(time::Duration::from_millis(250));
    // Increment the counter 
    i = (i+1)%4;
    // print a carriage return to clear the line
    print!("r")
  }
}

Answered by BookOwl on January 20, 2021

ForceLang, 130 bytes

Noncompeting, requires language features (datetime.wait) that postdate the question.

def w io.write
set z string.char 8
def d datetime.wait 250
w "Loading...  "
label 1
w z+"|"
d
w z+"/"
d
w z+"-"
d
w z+""
d
goto 1

Answered by SuperJedi224 on January 20, 2021

Pyth, 31 bytes

Wm,p+"rLoading... "d.d.25"|/-

Interpreter here.

Loading 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

Answered by insert_name_here on January 20, 2021

Snap!, 8 blocks

8 blocks of Snap!

This was one of the very first algorithms I ever puzzled out on an Apple ][e

Answered by wyldstallyns on January 20, 2021

Python 3, 86 83 bytes

GIF to follow. Golfing suggestions welcome as this is still a little verbose. -3 bytes thanks to Flp.Tkc.

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

Answered by Sherlock9 on January 20, 2021

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

Answered by Samuel on January 20, 2021

Swift 3, 75 bytes

do{"|/-\".characters.map{print("u{001B}[2JnLoading... ($0)");sleep(1)}}

I need to use u{001B} (ESCAPE) and [2J (clear screen) here because the old system API is deprecated in Swift 3 and I can't use r on Mac/Linux. I would lose bytes if I had to use the length posix_spawn call or NSTask. I also hate having to access a string's CharacterView in order to map over each character. At least I saved some bytes by using do instead of a while loop.

Answered by JAL on January 20, 2021

Node, 72 bytes (70 with literal)

c=0;setInterval(_=>console.log('x1BcLoading... '+'/-\|'[c=-~c%4]),250)

If you replace x1B with the literal escape character you can cut another 2 bytes. You don't need to call anything.

Answered by Piotr Wegner on January 20, 2021

Dyalog APL, 45 bytes

Uses instead of -.

{⍵⊣⎕DL÷4⊣⍞←⍵,⍨⊃⎕TC}¨⍣≢'|/─'⊣⍞←'Loading...  '

Loading...

⍞←'Loading... ' print the string without newline

'|/─'⊣ replace it with the string of bars

{...}¨⍣≢ indefinitely apply the below function on each character

⊃⎕TC first Terminal Control character (backspace)

⍵,⍨ prepend the argument (a bar character)

⍞← output that without newline (this overwrites the previous bar)

4⊣ replace that with a four

÷ invert that (yielding 0.25)

⎕DL DeLay that many seconds

⍵⊣ replace with (and return) the original argument

Answered by Adám on January 20, 2021

PowerShell 57 Bytes

for(){'|','','-','/'|%{"loading...$_";sleep -m 250;cls}}

Answered by jyao on January 20, 2021

HTML/CSS 135 Bytes

Like my previous answer, but doesn't use a monospace font, saving 6 bytes (not 100% if that's allowed, so I separated the answers for separate voting).

Update - a non monospace font is allowed. This works!

@keyframes l{0%{content:'|'}25%{content:'/'}50%{content:'-'}75%{content:'\'}}a:after{animation:l 1s infinite;content:'|'}
<a>Loading... 

Answered by Ben Aubin on January 20, 2021

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.)

Answered by udioica on January 20, 2021

Clojure, 93 92 bytes

#(do(print"Loading... -")(doseq[c(cycle"\|/-")](print(str"b"c))(flush)(Thread/sleep 250)))

Basically the Haskell answer (I swear I didn't cheat!).

It must be run in a console. IDE's REPL (Intellij) just prints a garbage character in place of the "b".

And it's late, and I've never even created a GIF before, so I'm going to have to pass on that part.

Answered by Carcigenicate on January 20, 2021

JavaScript (ES6), 90 bytes

(F=(i=0)=>{(c=console).clear();c.log('loading... '+'|/-\'[i]);setTimeout(F,250,-~i%4)})()

Answered by George Reith on January 20, 2021

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... ",'$'

Answered by Martin Rosenau on January 20, 2021

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.

Answered by LambdaBeta on January 20, 2021

C, 119 118 102 91 88 bytes

#import<windows.h>
i;f(){for(;;)Sleep(19*printf("rLoading... %c","\|/-"[i=(i+1)%4]));}

Answered by Steadybox on January 20, 2021

Mathematica, 90 bytes 85 bytes

Significantly longer than A Simmons' answer, but with fewer visual frills.

t=0;RunScheduledTask[t=Mod[t+1,4],1/4];Dynamic["Loading... "<>"|"["/","-","\"][[t]]]

Loading

Answered by ngenisis on January 20, 2021

T-SQL, 239 182 162 159 153 152 149 bytes

Golfed:

DECLARE @c CHAR(5)='|/-',@s CHAR,@ INT WHILE 1=1BEGIN SET @=1WHILE @<4BEGIN SET @s=(SELECT SUBSTRING(@c,@,1))PRINT'Loading... '+@s SET @=@+1 END END

Ungolfed

DECLARE @c CHAR(5) = '|/-',
        @s CHAR(1),
        @ INT;
WHILE (1 = 1)
BEGIN
    SET @ = 1;
    WHILE (@ < 4)
    BEGIN
        SET @s = (SELECT SUBSTRING(@c, @, 1));
        PRINT 'Loading... ' + @s;
        SET @ = @i + 1;
    END
END

Answered by Nelz on January 20, 2021

Bash, 62 bytes

c='|/-';for((;;)){ echo Loading... ${c:d++%4:1}^[M;sleep .25;}

where ^[ represents ESC (ASCII 0x1b), which typically you can get by pressing CtrlV and then ESC.

ESC M is RI, reverse linefeed.

If you don't care about running indefinitely, you can save 2 bytes by using a recursive function:

c='|/-';f(){ echo Loading... ${c:d++%4:1}^[M;sleep .25;f;};f

Answered by ninjalj on January 20, 2021

Nim, 81 80 bytes

import os
while 1>0:
 for c in "|/-\":stdout.write("rLoading... ",c);sleep 250

This may require flushing with stdout.flushFile in some terminals.

Answered by kvill on January 20, 2021

Ruby, 75 72 bytes

$><<'Loading...  '
c='|/-\'.chars
loop{$><<?b+c.rotate![0]
sleep 0.25}

Answered by Cyoce on January 20, 2021

><>, 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.

Answered by Leo on January 20, 2021

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 !

Answered by zeppelin on January 20, 2021

Befunge, 60 bytes

"  ...gnidaoL">:#,_v
"|/"<v*:*6"}",,8< 
"-"^>:#->#1_$:#^  _

Since Befunge doesn't have anything like a sleep command, the delay is approximated with a long running loop. This will obviously need to be adjusted depending on the speed of the system on which it is run.

You can test it on the codingground website.

Answered by James Holderness on January 20, 2021

C#, 165 123 bytes

Quite a few bytes saved thanks to raznagul !

z=>{Console.Write("Loading... ");for(int i=0;;i++){Console.Write(@"|/-"[i%=4]+"b");System.Threading.Thread.Sleep(250);}};

Anonymous function with no return type. The integer parameter z is only used as a placeholder in order to slash 1 byte off.

If input was allowed, the value 0 (or any other multiple of 4 to start from the same character) could be used as the iterator, reducing the byte count to 116 bytes:

i=>{Console.Write("Loading... ");for(;;i++){Console.Write(@"|/-"[i%=4]+"b");System.Threading.Thread.Sleep(250);}};

Full program with ungolfed function:

using System;

public class Program
{
    public static void Main()
    {
        Action<int> a = z =>
        {
            Console.Write("Loading... ");
            for (int i=0;;i++)
            {
                Console.Write(@"|/-"[i%=4]+"b");
                System.Threading.Thread.Sleep(250);
            }
        };

        a(0);
    }
}

No GIF for now, since I'm having trouble with some dependencies on a slightly older Linux distro... The cursor is displayed on the last character, this behavior can be changed by adding a space in the Loading... string.

Answered by adrianmp on January 20, 2021

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

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}

Answered by colsw on January 20, 2021

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);
        }
    }
}

Answered by Snowfire on January 20, 2021

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

Answered by Pete Arden on January 20, 2021

Mathematica, 74 67 Bytes

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

A whopping 7 bytes off thanks to @dahnoak

Answered by A Simmons on January 20, 2021

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.

Answered by hdrz on January 20, 2021

Java, 173 115 bytes

  • Version 2.0

Changed to lambda function/Thanks to @Xanderhall and @manatwork/115 bytes:

()->{System.out.print("Loading...  ");for(int i=0;;Thread.sleep(250))System.out.print("b"+"\|/-".charAt(i++&3));}
  • Version 1.0

Initial Version/173 bytes:

class A{public static void main(String[]a)throws Exception{System.out.print("Loading...  ");for(int i=0;;){System.out.print("b"+"\|/-".charAt(i++%4));Thread.sleep(250);}}}

Answered by Roman Gräf on January 20, 2021

C++11, 209 207 180 175 164 bytes

This might have been a good use for the new C++ literals, saving std::chrono::milliseconds(250) to just write 250ms or 0.25s, but unfortunately this requires using namespace std::chrono; which is longer in the end.

-2 bytes thanks to Flp.Tkc for using #import instead of #include. Saving lot more thanks to Flp.Tkc, learning about r and b. -2 bytes thanks to myself for c[++i%=4]. -5 bytes thanks to Roman Gräf. -9 bytes thanks to kvill for indexing into the string literal directly.

#import<iostream>
#import<thread>
int main(int i){A:std::cout<<"rLoading... "<<"|/-\"[++i%=4];std::this_thread::sleep_for(std::chrono::milliseconds(250));goto A;}

Golfed your initial example. If it does not work in your console, you have to add <<flush to see any output for +7 bytes.

Ungolfed:

#import <iostream>
#import <thread>

int main(int i) {
    A:
        std::cout << "rLoading... " << "|/-\"[++i%=4];
        std::this_thread::sleep_for(std::chrono::milliseconds(250));
    goto A;
}

Answered by Karl Napf on January 20, 2021

PHP, 58 bytes

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

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

Answered by Titus on January 20, 2021

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.

Answered by Denis Ibaev on January 20, 2021

Haskell (GHC), 103 91 bytes

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

Thanks @nimi for saving 12 bytes!

Answered by Angs on January 20, 2021

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.

Answered by Billywob on January 20, 2021

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

Answered by James on January 20, 2021

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.

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 2 bytes!

Answered by user6616962 on January 20, 2021

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)

Answered by Tyler MacDonell on January 20, 2021

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

Answered by marinus on January 20, 2021

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

Answered by Conor O'Brien on January 20, 2021

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.

Answered by Conor O'Brien on January 20, 2021

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>|/-

Answered by darrylyeo on January 20, 2021

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.

Answered by darrylyeo on January 20, 2021

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!

Answered by Zacharý on January 20, 2021

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 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.

Thanks to @Kade 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

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

Answered by Artyer on January 20, 2021

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

Answered by Luis Mendo on January 20, 2021

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.

Answered by Mama Fun Roll on January 20, 2021

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.

Answered by Neil on January 20, 2021

Perl 6, 72 61 bytes

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

Answered by Brad Gilbert b2gills on January 20, 2021

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

Answered by ETHproductions on January 20, 2021

Pyth - 36 35 bytes

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

Doesn't work online, obviously.

Answered by Maltysen on January 20, 2021

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

Answered by flawr on January 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP