Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is for(;;)?

I’ve been reading some code and saw a for loop with no statements, and I tryed to search what it meant and found nothing (probably because if I type something like "What is for(;;)" in google it just reads as if it was "What is for()"). I don’t know if it’s just a way to like disable a loop and make it not run (cause I tested it once and the code inside de loop didn’t run), though I would think people would just comment or erase the loop, and I’m just curious

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s quite the opposite of not running. It’s an infinite loop.

for(;;){
  console.log("test")
}

Open an new tab and you press F12 and then enter the code above in the developer console you will see that test gets printed quite often and your browser/ tab will get unresponsive quickly and your PC/ laptop might get louder as the cooler speeds up because the computer is busy looping.

So better quickly kill the tab where you’re running it or if you run it in Node kill the process with Ctrl + C.

The code above is equivalent to:

while(true){
  console.log("test")
}

The above is JavaScript, but that would also hold true for Java, C, C++, C#. Due to for(;;) being incorrect syntax for these languages it will not do anything in Kotlin, GoLang, Python, Rust, Swift or Groovy (and probably many others).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading