0

So I was making loops in a batch file which just keep going until you stop it. I wanted to do this in Javascript, but I wouldn't know how, because my understanding is that Javascript loops are only run once, and it only shows the output of the loop once.

Here is my loop:

@echo off
:loop
echo Hello!
goto loop

So when I put this into a batch file and run it, it will spam 'Hello!' until I close the program. That's what I want Javascript to do, but I don't quite know how to do that, and any help or input would be appreciated, thanks!

1
  • @Zachuks Javascript is browser based language. It has nothing to do with desktop application like batch files. What is your exact expectation about Javascript? Commented Apr 1, 2014 at 13:51

5 Answers 5

2
while (true) {
  // echo hello
}
Sign up to request clarification or add additional context in comments.

Comments

1

This can be achieved by simple while loop;

while(true){
   document.write("Hello!");
}

Comments

1

Try this:

while (1) {
  document.write("Hello!"); 
}

Comments

1

A more sensible scheme than a "raw" endless loop is to use the setTimeout or setInterval functions to make the browser not block while your code is running:

function fancy_output_func() {
    // bla
}

setInterval(fancy_output_func, 0);

2 Comments

I think this is what I want, because I did just the loop, and it won't load any content when I run it. Thanks!
You might also want to refrain from actually using a 0 there, this value is the interval in milliseconds so 100 should be enough most of the time.
0

I'm pretty sure there are some more ways to do that but here a a few

for(;;) { 
    //endless loop
}

while(1) {
    //endless loop
}

function a() {
    //endless loop
    a();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.