118
\$\begingroup\$

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!

\$\endgroup\$
19
  • 4
    \$\begingroup\$ Can submissions wait 0.25 seconds before initially displaying output? \$\endgroup\$ Nov 27, 2016 at 20:42
  • 2
    \$\begingroup\$ No, but thanks for mentioning that, I'll add it to the rules @ETHproductions \$\endgroup\$
    – FlipTack
    Nov 27, 2016 at 20:43
  • \$\begingroup\$ Is a trailing newline (after the animating symbol) acceptable? \$\endgroup\$
    – Copper
    Nov 27, 2016 at 20:43
  • \$\begingroup\$ Of course :) @Copper \$\endgroup\$
    – FlipTack
    Nov 27, 2016 at 20:44
  • 1
    \$\begingroup\$ @TheBitByte it means that, theoretically, nothing inside your program will cause it to error - such as a counter overflowing or reaching maximum recursion depth. \$\endgroup\$
    – FlipTack
    Dec 15, 2016 at 6:57

97 Answers 97

4
\$\begingroup\$

PHP, 58 bytes

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

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

\$\endgroup\$
5
  • \$\begingroup\$ @user59178: The assignment is needed to avoid integer overflow. Can you tell me how to run code with single and double quotes with -r? \$\endgroup\$
    – Titus
    Nov 28, 2016 at 14:29
  • \$\begingroup\$ Those are both excellent points, I probably should have actually tried running it, rather than just looking at the code.:-) \$\endgroup\$
    – user59178
    Nov 28, 2016 at 15:36
  • 1
    \$\begingroup\$ On 64-Bit php, it would take over 73 billion years to overflow. I think that's acceptably close to forever. Also, 57, no -r required: Loading... <?for(;;usleep(25e4))echo'\|/-'[$i=++$i%4],~÷; \$\endgroup\$
    – primo
    Dec 2, 2016 at 12:45
  • \$\begingroup\$ @primo: I tried ^H, but it doesn´t seem to expand to chr(8) everywhere. And no idea what it depends on. \$\endgroup\$
    – Titus
    Dec 8, 2016 at 15:52
  • \$\begingroup\$ If using -r, it will likely depend on the terminal. \$\endgroup\$
    – primo
    Dec 8, 2016 at 19:54
4
\$\begingroup\$

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.
\$\endgroup\$
5
  • 1
    \$\begingroup\$ True1=1 and that way you can remove the following space too. \$\endgroup\$
    – manatwork
    Nov 28, 2016 at 10:26
  • 1
    \$\begingroup\$ Better use a single output statement rewriting the entire line: Write(#13'Loading... ',c);. (BTW, no need for , between character and string literals.) \$\endgroup\$
    – manatwork
    Nov 28, 2016 at 10:32
  • \$\begingroup\$ @manatwork - thanks, that makes more sense \$\endgroup\$
    – hdrz
    Nov 28, 2016 at 10:34
  • \$\begingroup\$ Oh, and no need for the ; in front of 1st end. \$\endgroup\$
    – manatwork
    Nov 28, 2016 at 10:38
  • \$\begingroup\$ Got it. have to eat something.... \$\endgroup\$
    – hdrz
    Nov 28, 2016 at 10:57
4
\$\begingroup\$

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);}}}
\$\endgroup\$
3
  • 6
    \$\begingroup\$ “Your program should be able to run indefinitely.” – This will terminate when reaches Integer.MAX_VALUE after 17++ years with “java.lang.StringIndexOutOfBoundsException: String index out of range: -3”. \$\endgroup\$
    – manatwork
    Nov 28, 2016 at 11:08
  • \$\begingroup\$ Can't test but will it i&3 do? \$\endgroup\$ Nov 28, 2016 at 14:27
  • 1
    \$\begingroup\$ Also, you are allowed to submit a function. You can get rid of the class declaration and just have void a(){myfunction} format. \$\endgroup\$
    – Xanderhall
    Nov 28, 2016 at 14:39
4
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ print$><< \$\endgroup\$
    – manatwork
    Nov 28, 2016 at 9:30
  • \$\begingroup\$ @manatwork Oh, cool! \$\endgroup\$ Nov 28, 2016 at 12:09
  • \$\begingroup\$ You can use $. instead of initializing i, as explained here. Saves at least two bytes \$\endgroup\$
    – daniero
    Nov 30, 2016 at 17:43
4
\$\begingroup\$

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>

\$\endgroup\$
2
  • \$\begingroup\$ This is a pretty neat language. Welcome to PPCG :) \$\endgroup\$
    – FlipTack
    Dec 28, 2016 at 0:01
  • \$\begingroup\$ @FlipTack Thank you:) This place is like a giant playground:)lol \$\endgroup\$
    – tkellehe
    Dec 28, 2016 at 0:40
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Would this reach maximum recursion depth and crash? \$\endgroup\$
    – FlipTack
    Nov 29, 2016 at 6:51
  • \$\begingroup\$ 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. \$\endgroup\$ Nov 29, 2016 at 6:56
3
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I think this doesn't fulfill the third rule a i++ will eventually throw an overflow exception. \$\endgroup\$
    – raznagul
    Nov 28, 2016 at 15:41
  • 2
    \$\begingroup\$ It won't overflow, since i is assigned the modulo of division by 4 when printing the line (i%=4). \$\endgroup\$
    – adrianmp
    Nov 28, 2016 at 15:57
  • 1
    \$\begingroup\$ +1 this is indeed clever. You can save a lot of bytes by printing Loading once and then printing "\b" instead of setting the cursor position. Also you don't have to define r. You can use @"|/-\"[...] instead. \$\endgroup\$
    – raznagul
    Nov 28, 2016 at 16:10
  • 1
    \$\begingroup\$ I don't know if it is allowed. But you add on byte for the initialization of z and then you z instead of i, in total saving 6 bytes. \$\endgroup\$
    – raznagul
    Nov 28, 2016 at 16:16
3
\$\begingroup\$

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 "\n\eM", 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 "\n\x8d" 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).

\$\endgroup\$
0
3
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ The @echo off line is costing you ten bytes. Would it be cheaper to simply place an @ on each command individually? Or is there some reason that doesn't work? \$\endgroup\$
    – user62131
    Dec 4, 2016 at 8:48
  • \$\begingroup\$ @ais523 It's giving me some errors... I'm working on it \$\endgroup\$
    – undo
    Dec 4, 2016 at 8:50
  • \$\begingroup\$ @ais523 Done! Turns out if you're using DO ( ) with FOR, you just need to put a single @: DO @( ) \$\endgroup\$
    – undo
    Dec 4, 2016 at 8:57
  • 1
    \$\begingroup\$ Since nobody's said it, welcome to code-golf! Nice answer \$\endgroup\$
    – FlipTack
    Dec 4, 2016 at 16:29
  • \$\begingroup\$ Still better than my 100-byte bash answer! \$\endgroup\$
    – ckjbgames
    Feb 3, 2017 at 15:13
3
\$\begingroup\$

PowerShell, 116 77 69 67 bytes

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

cleaner than cls?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$
    – FlipTack
    Dec 15, 2016 at 19:14
3
\$\begingroup\$

C, 119 118 102 91 88 bytes

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

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Could char *c be char*c? \$\endgroup\$
    – Adalynn
    Nov 28, 2016 at 21:20
  • 1
    \$\begingroup\$ Can you move the assignment into the index, for(;;){printf("\b%c",c[i=i>2?0:i+1])...? \$\endgroup\$
    – Adalynn
    Nov 28, 2016 at 21:39
  • 1
    \$\begingroup\$ Have a look at my submission... i=i>2?0:i+1 is identically i=(i+1)%4. He can use incrementation in the index, then modulo in the loop. \$\endgroup\$
    – LambdaBeta
    Nov 28, 2016 at 21:41
  • 1
    \$\begingroup\$ He can also save a byte (I think) by completely flushing with \r so he doesn't need the extra space in the "Loading... " string. \$\endgroup\$
    – LambdaBeta
    Nov 28, 2016 at 21:42
  • 1
    \$\begingroup\$ I don't know C, but would i=++i%4 work? \$\endgroup\$
    – FlipTack
    Dec 28, 2016 at 18:04
3
\$\begingroup\$

ES8 + HTML, 68 bytes

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

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;
}
\$\endgroup\$
11
  • \$\begingroup\$ Will i overflow? \$\endgroup\$
    – Adalynn
    Nov 28, 2016 at 13:43
  • \$\begingroup\$ @ZacharyT Ah, yes it would and negative % positive = negative in C++. Rolled back. \$\endgroup\$
    – Karl Napf
    Nov 28, 2016 at 14:15
  • 1
    \$\begingroup\$ Tip: use #import<...> to save a couple bytes :) \$\endgroup\$
    – FlipTack
    Nov 28, 2016 at 15:08
  • 1
    \$\begingroup\$ No need to define c, just use ...<<"|/-\\"[++i%=4] for another couple of bytes. \$\endgroup\$
    – kvill
    Nov 28, 2016 at 18:47
  • 1
    \$\begingroup\$ @kvill Thanks! That feels a little pythonish. \$\endgroup\$
    – Karl Napf
    Nov 28, 2016 at 19:03
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ don't know nim but can't you write the for loop directly after the while 1>0;? Also can you maybe remove the whitespace between in and '|/-\\":? \$\endgroup\$ Nov 28, 2016 at 20:00
  • \$\begingroup\$ @RomanGräf Thanks, but those changes are beyond Nim! \$\endgroup\$
    – kvill
    Nov 28, 2016 at 20:53
2
\$\begingroup\$

PowerShell 57 Bytes

for(){'|','\','-','/'|%{"loading...$_";sleep -m 250;cls}}
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to PPCG! You can save a byte by using a char array instead of explicitly calling out each character -- [char[]]'|\-/' \$\endgroup\$ Nov 29, 2016 at 16:53
  • \$\begingroup\$ Right, @TimmyD, Thx! \$\endgroup\$
    – jyao
    Nov 29, 2016 at 17:21
2
\$\begingroup\$

Ruby, 75 72 bytes

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

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

\$\endgroup\$
2
  • \$\begingroup\$ Wow! "|"["/", "-", "\\"][[t]] looks awesome. nice one! :) \$\endgroup\$
    – Dan Oak
    Nov 29, 2016 at 4:54
  • 2
    \$\begingroup\$ Nice job! I count only 86 bytes (using the two-byte [[ and ]] instead of the three-byte and ). You can also save a byte with 1/4 in place of 0.25. \$\endgroup\$ Nov 30, 2016 at 5:47
2
\$\begingroup\$

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

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

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
\$\endgroup\$
2
  • \$\begingroup\$ Maybe you should try golfing this? \$\endgroup\$
    – Cyoce
    Nov 29, 2016 at 16:08
  • \$\begingroup\$ @Cyoce down to 182. \$\endgroup\$
    – Nelson
    Nov 29, 2016 at 16:22
2
\$\begingroup\$

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.

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

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.

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

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

\$\endgroup\$
2
  • \$\begingroup\$ The 0% frame seems unnecessary. \$\endgroup\$
    – manatwork
    Nov 29, 2016 at 8:41
  • \$\begingroup\$ @manatwork there so that it can repeat infinitely. \$\endgroup\$
    – Ben Aubin
    Dec 13, 2016 at 18:53
2
\$\begingroup\$

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.

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

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.

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

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]);}
\$\endgroup\$
2
\$\begingroup\$

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.

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

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

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

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

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$
    – DJMcMayhem
    May 25, 2017 at 22:22
1
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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