0

I'm trying to make a function that runs a specified piece of code forever. How can I do this?

Example:

function forever(code) {
   for (let i = 1; i > 0; i++) {
      //Run code from variable here
   }

I've tried:

function forever(code) {
   for (let i = 1; i > 0; i++) {
      code
   }
TheC0mpu1er
  • 119
  • 1
  • 5

1 Answers1

1

Just use the while loop.

function forever(code) {
  while (true) {
    console.log("Running forever");
  }
}

forever();
DecPK
  • 24,537
  • 6
  • 26
  • 42