- 1). Find the place in code where you want to place the infinite loop. Sometimes there may be a large chunk of code you want running infinitely, while other times it may just be a location in a program. Any code that is written after an infinite loop will not run.
- 2). Choose the type of statement you wish to use to create an infinite loop. You could want to use a do-while loop or a for statement. Regardless of which statement you choose, it can be done with one line of code.
- 3). Determine which programming language to use. Most languages have similar ways of doing the same thing, but syntax will be unique to the language.
- 4). Create the statement. A do-while loop can be written as while(true){}; in C++. Similarly, in C++ you could write a for loop as for(float i = 0; i != 1.1; i++){}. Either line of code creates an infinite loop in the program, causing your program to run until manually exited.
next post