Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Loading... Forever

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!

Answer*

Draft saved
Draft discarded
Cancel
7
  • \$\begingroup\$ Would T eventually overflow? \$\endgroup\$ Commented Nov 28, 2016 at 8:13
  • \$\begingroup\$ @Flp.Tkc It wouldn't overflow but be treated as infinity past 1e+308 in which case NA is returned so I guess this answer is invalid then (didn't notice it in the rules). Will update soon \$\endgroup\$ Commented Nov 28, 2016 at 8:47
  • 1
    \$\begingroup\$ Actually you can get it 2 bytes shorter if you don't use the built-in T: i=1;repeat{cat("\rLoading...",c("\\","|","/","-")[i]);Sys.sleep(.25);i=`if`(i>3,1,i+1)} is 87 bytes. \$\endgroup\$ Commented Nov 29, 2016 at 16:15
  • 2
    \$\begingroup\$ ... or T=T%%4+1: even 2 bytes shorter. \$\endgroup\$ Commented Dec 8, 2016 at 14:58
  • 1
    \$\begingroup\$ 79 bytes :) \$\endgroup\$ Commented Oct 4, 2017 at 13:59

AltStyle によって変換されたページ (->オリジナル) /