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
11
  • \$\begingroup\$ Still waiting for it to display "\"... \$\endgroup\$ Commented Nov 28, 2016 at 13:09
  • \$\begingroup\$ @manatwork Oh crap, lazy copy and pasting. Will fix it when I'm back at my desk shortly :) \$\endgroup\$ Commented Nov 28, 2016 at 13:16
  • \$\begingroup\$ Sorry to see your solution getting longer due to my comment. Can't you use 1>0 instead of true to get it back to 186? \$\endgroup\$ Commented Nov 28, 2016 at 13:37
  • \$\begingroup\$ @ErikGolferエリックゴルファー, no idea about C#, but based on the fact the language is a copy of Java and apparently confirmed by Can't cast int to bool, I thought that would not work. (BTW, if that works, maybe using the first call of l() as condition would also work?) \$\endgroup\$ Commented Nov 28, 2016 at 14:00
  • 2
    \$\begingroup\$ @manatwork Well, it seems C# is ungolfable. \$\endgroup\$ Commented Nov 28, 2016 at 14:01

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