| Bytes | Lang | Time | Link |
|---|---|---|---|
| 121 | Swift 6 | 250302T012837Z | macOSist |
| 535 | Bespoke | 250325T092631Z | Josiah W |
| 083 | tcl | 170106T015532Z | sergiol |
| 060 | Casio BASIC fx9750GIII | 240910T141115Z | madeforl |
| 194 | Mindustry | 241011T191353Z | Dornteuf |
| 027 | Japt | 240911T151226Z | Shaggy |
| 086 | GNU AWK | 240713T190737Z | Pedro Ma |
| 086 | hyperscript | 240713T140759Z | noodle p |
| nan | JavaScript + HTML | 240331T135645Z | noodle p |
| 039 | Uiua | 240330T171255Z | noodle p |
| 036 | Easyfuck | 240326T013303Z | Quadrupl |
| 122 | YASEPL | 240208T191154Z | madeforl |
| 356 | CLCINTERCAL psyscall | 240202T034321Z | 鳴神裁四点一号 |
| 098 | Scratch | 240125T012009Z | noodle p |
| 071 | C89 | 240124T184221Z | c-- |
| 065 | TIBASIC | 230728T045216Z | joyofori |
| 031 | Pyth | 161130T065124Z | insert_n |
| 036 | MATL | 161127T213519Z | Luis Men |
| 056 | Zsh | 220312T065710Z | pxeger |
| 093 | Python 3 | 220311T225329Z | Larry Ba |
| 108 | Python 3 Windows | 210610T085152Z | raspidui |
| 061 | Julia | 210609T222647Z | MarcMush |
| 026 | 05AB1E | 210609T203150Z | Makonede |
| 040 | reticular | 161128T032544Z | Conor O& |
| 024 | Stax | 210226T073341Z | Razetime |
| 060 | Groovy | 180517T111218Z | Matias B |
| 083 | Yabasic | 180517T105618Z | Taylor R |
| 033 | ><> with t.03 flag | 180517T090149Z | Jo King |
| 038 | Japt | 180517T065251Z | Bubbler |
| 224 | C++ | 180112T172408Z | Colin Ro |
| 074 | JavaScript ES6 + HTML | 170512T134537Z | Shaggy |
| 073 | C function | 170525T222008Z | epimatec |
| 068 | ES8 + HTML | 171004T133749Z | copyrepl |
| 056 | PHP | 170702T043903Z | kip |
| 121 | TSQL | 170702T025043Z | WORNG AL |
| nan | 170619T103054Z | Twometer | |
| 034 | Charcoal | 170619T091225Z | ASCII-on |
| 082 | C | 170513T020523Z | MD XF |
| 008 | Snap! | 161130T061946Z | wyldstal |
| 059 | shortC | 170522T000841Z | MD XF |
| 109 | C++ | 170512T144706Z | Clé |
| 094 | Python 3 | 161223T203850Z | python-b |
| 140 | C# | 170131T104149Z | Metoniem |
| 100 | Bash | 170130T203330Z | ckjbgame |
| 048 | PKod | 170201T161559Z | Offtkp |
| 123 | Commodore 64 or VIC20 | 170131T172334Z | Shaun Be |
| 046 | SmileBASIC | 170130T083411Z | 12Me21 |
| 057 | SmileBASIC | 170131T134205Z | snail_ |
| 025 | Noodel | 161227T223841Z | tkellehe |
| 143 | HTML/CSS | 161127T212251Z | Neil |
| 079 | tcl | 170106T021730Z | sergiol |
| 088 | C | 161128T210957Z | Steadybo |
| 057 | TIBasic CE/CSE only | 161228T201531Z | Julian L |
| 046 | awk | 161228T092319Z | James Br |
| 067 | PowerShell | 161214T214013Z | Dan |
| 135 | HTML/CSS 135 Bytes | 161129T032620Z | Ben Aubi |
| 092 | Clojure | 161129T010129Z | Carcigen |
| 189 | Turing machine simulator | 161213T174928Z | Erik the |
| 077 | Python 2 | 161127T214639Z | Artyer |
| nan | HTML + JS ES6 | 161127T224908Z | darrylye |
| 057 | Powershell v4 | 161128T135036Z | colsw |
| nan | Windows Batch | 161128T062239Z | user6616 |
| 077 | Batch | 161204T082132Z | undo |
| 081 | F# interactive | 161203T222035Z | pmbanka |
| 109 | C# | 161202T123656Z | Gonç |
| 283 | NASM x86_64 | 161129T213154Z | Samuel |
| 086 | Scala | 161201T203246Z | corvus_1 |
| 061 | Befunge 98 | 161130T213700Z | ninjalj |
| 057 | Ruby | 161201T170323Z | daniero |
| 073 | Forth | 161128T155018Z | zeppelin |
| 149 | TSQL | 161128T200453Z | Nelson |
| 111 | C# | 161201T085659Z | Luc |
| 056 | MSDOS .COM file | 161128T213749Z | Martin R |
| 083 | Python 3 | 161130T061117Z | Sherlock |
| 057 | Ruby | 161128T030717Z | Conor O& |
Swift 6, 108 123 121 bytes
C interop, gooooooooooooooooo...
import Darwin
let s=stdout
fputs("Loading... |",s)
while 0<1{"|/-\\".map{fputs("\u{8}\($0)",s)
fflush(s)
usleep(250000)}}
We print to Never mind, sometimes reading the question in full is a good idea.stderr instead of stdout because stderr isn't buffered by default; this saves me a call to fflush(_:).
We use fputs(_:) instead of puts(_:) to avoid the trailing newline. (And before anyone asks, no, we can't just use printf, because printf, being a C function that uses the ... syntax for varargs, is not available in Swift.)
Bespoke, 535 bytes
PUT XX:DIGITNINE BI
PUT XX:FOUR FIFTH
PUT XX:FOUR SEVENTH
PUT XXX:I BI FOUR
PUSH I H V
PUT XX:TRI BI
PUT XX:FOUR SEXTET
DO COPY
DO COPY
PUT XXX:I NUMBERZERO TRI
PUT XXX:I I NUMBERZERO
PUT XXX:I NUMBERZERO FIFTH
PUT XXX:I NUMBERZERO NUMBERZERO
PUT XX:DIGITNINE SEVENTH
PUT XXX:I I I
PUT XX:SEVENTH SEXTET
PUSH I
CONTROL WHILE
OUTPUT CH
DO COPY
CONTROL END
CONTROL DOWHILE
DO COPY
PUT XXXX:FIFTH I I I;STACKTOP QUOTIENTOF
PUSH FOUR STACKTOP MODULO
PUSH BI STACKTOP PLUS
DO COPYN
OUTPUT CH
PUSH INTEIGHT;OUTPUT CH
STACKTOP PLUSONE
DO COPY
Note: at the speed that the Python-based Bespoke interpreter runs on my computer, a time interval close enough to 0.25 seconds happens every 5111 iterations of my program's main loop. Bespoke has no command for waiting a specific length of time.
(Also, the arithmetic I do on my counter will theoretically take longer and longer to do as it gets higher, because of the way ints work in Python. I can rewrite my program if this is an issue.)
tcl, 83
while 1 {lmap c {| / - \\} {puts -nonewline \rLoading...$c;flush stdout;after 250}}
Can be seen running on: http://tpcg.io/_6PBTFX
Unfortunately, this online compiler can not demonstrate it going back rewriting the line. In a local machine it can be seen.
Casio BASIC (fx-9750GIII), 64 60 bytes
"Loading..."
Lbl A
1+Ans Rmdr 4
Locate 12,1,StrMid("\\|/-",Ans,1)
For 0→I To 200
Next
Goto A
The timing is probably not accurate since the Casio fx-9750giii doesn't have any built-in time functions as far as I know, but I think I got pretty close.
Timing ranges on what device you use this on, since it uses a for loop to separate the frames.
Mindustry, 194 bytes
set s "|"
print "Loading... "
print s
printflush
wait 0.25
jump 8 notEqual s "|"
set s "/"
jump 1 equal
jump 11 notEqual s "/"
set s "-"
jump 1 equal
jump 0 notEqual s "-"
set s "\"
jump 1 equal
Must be connected with a message block (message1), which is used as stdout.
An interesting golf in this program is jump 1 equal: this is shorter than jump 1 always by 1 byte, and works due to the default arguments for jump being notEqual, x and false.
It expands to jump 1 equal x false, which is evaluated as true, because x is null and null s apparently equal to false. (Reminds me of strange JS comparisons.)
I'll add a GIF of it later.
Japt, 29 27 bytes
Oq`LoÃHg... {°g"|/-\\"#út@ß
Oq`...{°g"..."#út@ß
Oq :Overwrite the output with
`... : Compressed string "Loading... "
{ : Interpolate
° : Postfix increment the first input variable (defaults to 0)
g"..." : 0-based index into the literal string
#ú :250
t :Set a timeout of 250ms
@ :To run the following function
ß : Recursive call
GNU AWK, 86 bytes
Run it on your terminal:
gawk -ltime 'BEGIN{for(printf"Loading... |";sleep(1/4)++k;)printf"\b"substr("|/-\\",k%4+1,1)}'
80 chars of code + 6 chars for arguments
This is just GNU AWK relying on its time extension and respecting all rules. No input, no BASH, no coreutils. Could be shorter, but the sleep function must be called after the first printf.
gawk -ltime Runs GAWK with time extension.
Exactly the same as using @load "time", but shorter.
'
BEGIN{
for( Begins the loop without input.
printf"Loading... |"; Starts printing the first iteration without trailing line.
sleep(1/4)++k; Waits .25 second, which returns 0, and appends to the counting variable.
No big deal here. I just did it to save characters.
;)
printf
"\b" Prints a backspace
substr("|/-\\", appended to a sub-string of this monstrosity (\ is escaped)
k%4+1, starting at the character mod 4 + 1 (GAWK starts counting at 1)
1) with length 1.
'
hyperscript, 86 bytes
Loading... <x _="init repeat forever increment n put '\\|/-'[n mod 4]into me wait 250"
Try it:
<script src="https://unpkg.com/hyperscript.org@0.9.8"></script>
Loading... <x _="init repeat forever increment n put '\\|/-'[n mod 4]into me wait 250"
init -- when the document is initialized
repeat forever
increment n -- increment initializes n to 0
put '\\|/-'[n mod 4]into me -- sets <x>'s innerHTML
wait 250 -- (250 milliseconds)
JavaScript + HTML, 48 + 20 = 68 bytes
setInterval(_=>a.innerHTML="\\|/-"[i++%4],i=250)
Loading... <a id=a>|
Since the animation is supposed to start immediately, I had to move the Loading text and the initial state of the animation to the HTML.
Uiua, 39 bytes
⍢(&sl1/4&pf⊂"\rLoading... "⊢.↻1)1$ |/-\
For some reason it looks really slow in the GIF but I can assure you on my computer it waits for 1/4 of a second. You may also notice that in the GIF, the code has an extra backslash; that's because I have Uiua 0.9.5 installed on my computer. In 0.10.0, the way $ strings work is a bit different, and the extra backslash isn't needed.
Explanation:
⍢(…)1$ |/-\
This starts with “|/-\” on the stack and does the rest of the program in a loop forever. A byte is saved by using the raw string syntax $ |/-\ instead of the normal "|/-\\".
↻1
Rotate this string one character to the left.
&pf⊂"\rLoading... "⊢.
Combine the first character of this with the loading text, and print it. The \r causes the text to be printed over whatever was already there.
&sl1/4
Sleep for a quarter of a second. Using a fraction literal like this is a byte shorter than 0.25.
Easyfuck, 41 36 bytes
ymsĘ·^U¶ąĺw‹ž]€ ĎÁ␆n␈2´A•ŕ␐.\»>í90ďSOS
due to lack of unicode representations for c1 control characters, they have been replaced by their superscripted abbreviations
Decompressed:
<[.<U]<U[.<W<.<]@␈␙|␈␙\␈␙-␈␙/␀ ...gnidaoL
<[.<U]<U[.<W<.<]@␈␙|␈␙\␈␙-␈␙/␀ ...gnidaoL
< go to the last cell
[.<U] go through cells backwards, printing and deleting until encountering a null character
<U delete the null character
[.<W<.<] go backwards through characters looping when reaching the beginning, printing and waiting according to their values
@ marks the end of code
␈␙|␈␙\␈␙-␈␙/␀ ...gnidaoL initializer data
YASEPL, 122 bytes
=sŔ,9=1)pipeſdivideſminusſ"\"=b$27»ſopenbracket=o|3`1!aŔ,9!c$a-s}1,250,3|`3!b~#"2J"~#"HLoading..."=g¥o,1~!o+%4!Ŕ,9|
it starts automatically, the compiler just takes a second to load the file so thats why there is a pause if you run this
I cant exactly make a GIF of this right now, but when I can i'll update.
this uses ANSI.
CLC-INTERCAL -psyscall, 356 bytes
Uses latest feature: syscall #9.
DO;1<-#12DO;1SUB#1<-#94DO;1SUB#2<-#317DO;1SUB#3<-#314DO;1SUB#4<-#2567DO;1SUB#5<-#377DO;1SUB#6<-#364DO;1SUB#7<-#248DO;1SUB#8<-#670DO;1SUB#9<-#188DO;1SUB#10<-#255DO;1SUB#11<-#255DO;1SUB#12<-#213DO;2<-#1DO:9<-#392¢#452DOCOMEFROM#9(4)DO;2SUB#1<-#122(2)DO;2SUB#1<-#126(1)DO;2SUB#1<-#15DO;2SUB#1<-#47DO.1<-#8DOCOMEFROM.1DOREADOUT;1+;2(666)DO.9<-#9(9)DO.1<-.1~#14
Running gif before fixing; spinning counterclockwise
Ungolfed
DO;1<-#12 DONOTE ;1 <- "\rLoading... "
DO;1SUB#1<-#94
DO;1SUB#2<-#317
DO;1SUB#3<-#314
DO;1SUB#4<-#2567
DO;1SUB#5<-#377
DO;1SUB#6<-#364
DO;1SUB#7<-#248
DO;1SUB#8<-#670
DO;1SUB#9<-#188
DO;1SUB#10<-#255
DO;1SUB#11<-#255
DO;1SUB#12<-#213
DO;2<-#1 DONOTE ;2 is one of "|/-\"
DONOTE implicit .1<-#0 as iterator
DO:9<-#392¢#452 DONOTE const 250,000
DOCOMEFROM#9
(4)DO;2SUB#1<-#122 DONOTE /
(2)DO;2SUB#1<-#126 DONOTE -
(1)DO;2SUB#1<-#15 DONOTE \
DO;2SUB#1<-#47 DONOTE |
DO.1<-#8
DOCOMEFROM.1 DONOTE possibly from 4 2 or 1
DOREADOUT;1+;2
(666)DO.9<-#9 DONOTE sleep for :9 microseconds
(9)DO.1<-.1~#14 DONOTE right shift
Scratch, 98 bytes
define
forever
set[i v]to(((i)mod(4))+(1
say(join[Loading... ](letter(i)of[|/-\\]))for(.25)seconds
C89, 71 bytes
main(i){for(;;)usleep(4<<printf("Loading... %c\n[A","/-\\|"[i++&3]));}
Using printable characters the format argument to printf(3) would be "Loading... %c\n\x1b[A".
C (gcc) -O3, 65 bytes
The same but as a function. Requires tail-call optimization, otherwise it would overflow the stack eventually.
i;f(){f(usleep(4<<printf("Loading... %c\n[A","/-\\|"[i++&3])));}
/* main(){f();} */
TI-BASIC, 65 bytes
While 1:remainder(A+1,4)→A:Output(1,1,"Loading... "+sub("|/-\",A+1,1:Wait 1/4:End
TI CONNECT CE sadly does not allow screen recording so you'll have to enjoy my amazing camera skills instead.
Ungolfed:
While 1
remainder(A+1,4)→A
Output(1,1,"Loading... "+sub("|/-\",A+1,1
Wait 1/4
End
Explained:
While 1 Loop through everything forever
remainder(A+1,4)→A Set A to (A+1) mod 4
Output(1,1 Print at the first row, first column
"Loading..." Loading...
+ Concatenate string to...
sub( .... ,A+1,1 The A+1th characer of...
"|/-\" This string
Wait 1/4 Pause for 0.25 seconds
End End loop, go back to while.
According to this meta post, TI-BASIC is scored by token byte count, not characters. While is stored as a 1 byte token, and so is Output, while remainder is two bytes. It's kind of hard to count the tokens, so the best way is just to go to TI CONNECT and see how much space the program takes on the calculator.
Pyth, 31 bytes
Wm,p+"\rLoading... "d.d.25"|/-\
Interpreter here.

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
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:
Or try it at MATL Online!
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
Python 3, 93 bytes
import time
while 1:print(end="Loading... "+"|/-\\"[int(time.time())%4]+"\r");time.sleep(.25)
Python 3 (Windows), 112 109 108 bytes
import time,os
while 1:
for i in ['|','/','-','\\']:print("Loading... "+i);time.sleep(1/4);os.system('cls')
Python 3 (*nix), 111 110 bytes
import time,os
while 1:
for i in ['|','/','-','\\']:print("Loading... "+i);time.sleep(1/4);os.system('clear')
Thanks @Dion for reducing 3 bytes in Windows version and add more info about *nix run!
Julia, 61 bytes
while 0!=@.print("\rLoading... "*["|/-\\"...])==sleep(1/4)end
05AB1E, 26 bytes
[13甲½... ”"|/-\"NèJ?Ƶ–.W
[13ç”...”"..."NèJ?Ƶ–.W # trimmed program
[ # forever...
ç # push character with codepoint...
13 # literal
”...” # push "Loading... "
è # push character in...
"..." # literal...
è # at index...
N # current index in loop...
è # modulo length of...
"..." # literal
? # output...
J # joined stack...
? # without trailing newline
.W # wait...
Ƶ– # 250...
.W # milliseconds
reticular, 40 bytes
:i=@C"Loading... "o"|/-\\".iHo14%w.i1+4,
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
Stax, 24 bytes
Ñ!Δ╚«&╖ô^ô◙⌠≈%<╗∞█z9ÖºOT
Delays 15 frames between each change, which at default 60fps should be equal to 1/4th of a second.
Explanation
W`lAtv>!`"|/-\"{[+p{|,}15*|:F
W loop forever
`lAtv>!` push "Loading... "
"|/-\"{ F for each char in "|/-\"
[+p add to Loading and print
{|,}15* delay 1 frame 15 times
|: clear the screen
Groovy, 60 bytes 59 bytes, 61 bytes
print'Loading...';for(;;)'|/-\\'.any{print"$it\b";sleep 250}
(modified to work with later versions of groovy, removed ascii cast)
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
><> with -t.03 flag, 33 bytes
'o!vooooo|\-/ ...gnidaoL
{[4<o8o:
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.
Japt, 38 bytes
@Oq Oo`LoÃHg... `+"|/-\\"gW°%4)1
a#úiU
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).
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;}}
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>
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
ES8 + HTML, 68 bytes
setInterval(e=>a.innerHTML='|/-\\'[++i%4],i=250)
Loading... <a id=a>-
PHP, 56 bytes
while(!usleep(25e4))echo"\rLoading... ",'\|/-'[@$i++%4];
T-SQL, 121 bytes
DECLARE @ CHAR W:SET @=IIF(@='/','-',IIF(@='-','\',IIF(@='\','|','/')))PRINT'Loading... '+@ WAITFOR DELAY'0:0:0.25'GOTO W
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:
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.
C, 92 89 82 bytes
i;f(){for(;;i=4)while(i--)dprintf(2,"\rLoading... %c","|\\-/"[i]),usleep(250000);}
Snap!, 8 blocks

This was one of the very first algorithms I ever puzzled out on an Apple ][e
shortC, 59 bytes
i;f(){O;;i=4)Wi--)dR2,"\rLoading... %c","|\\-/"[i]),U250000
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]);}
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
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)
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.
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.
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.
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.
SmileBASIC, 51 46 bytes
CLS?"Loading... ";"|\-/"[3AND MAINCNT/15]EXEC.
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
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
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>
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.
tcl, 79
while 1 {lmap c {| / - \\} {puts -nonewline stderr \rLoading...\ $c;after 250}}
assuming I can write to stderr instead of stdout
C, 119 118 102 91 88 bytes
#import<windows.h>
i;f(){for(;;)Sleep(19*printf("\rLoading... %c","\\|/-"[i=(i+1)%4]));}
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.
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"\033[1A"}
Try it:
$ echo \|/-\\|awk -F '' '{while(i=1+i%4)print"Loading... "$i"\033[1A"}'
Loading...[|/-\]
One byte comes off if . I didn't wait to see if NF is replaced with 4i iterates to oblivion.
PowerShell, 116 77 69 67 bytes
for(){[char[]]'|/-\'|%{write-host -n `rLoading... $_;sleep -m 250}}
cleaner than cls?
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...
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.
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.
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:
I tested it on a Linux VM too. I couldn't test it on a Mac.
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.
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.
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}
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 ( The delay is done with |) into the array, so I had to manually add it with another assignment.PING, which might not be accurate.
Output:
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!
Batch, 88 81 77 bytes
:1
@FOR %%G IN (/,-,\,^|) DO @(echo Loading...%%G
timeout/t 1 >a
cls)
@goto 1
(My first answer on Code Golf...)
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 :)
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:
Edit: Simplified the array.
Edit2: For is way better for this.
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
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.
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).
Ruby, 57 bytes
Same length as Conor O'Brien's answer, but a different approach:
%w(| / - \\).cycle{|c|$><<"Loading... #{c}\r";sleep 0.25}
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
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
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);
}
}
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... ",'$'
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
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 I had to rework the string, so now the '...' strings don't need to have double-escapes\ is at the end and must be escaped.



















