How Can Infinite Loops Be Created?

How Can Infinite Loops Be Created? thumbnail
Infinite loops can create a great deal of stress when programming.

In computing, an infinite loop is a sequence of instructions (or code) that will repeat endlessly, as there is no condition that would cause the instructions to terminate. It is generally not a goal to create an infinite loop; however, detecting infinite loops in your code can help diagnose and fix any bus related to your program. If you would like to deliberately create an infinite loop (e.g., for demonstration purposes), there are several ways to do so. An example is given below.

Things You'll Need

  • Basic knowledge of computer programming
  • Knowledge of pseudocode
Show More

Instructions

    • 1

      Define a variable. For example

      x = 1

      means that the number 1 is stored in the variable x.

    • 2

      Create a loop whose conditions will either always be true, or never be met. For example, the condition

      IF x !=2

      will always be true, as x is defined as 1, so the statement x=2 will never be true.

      The condition

      while x > 1

      will also never be true, as x will never be greater than 1 (as the variable x is defined as 1).

    • 3

      Create an instruction to be executed within the loop. For example, write the statement "This is an infinite loop" inside the loop. In pseudocode, the entire program may look like this

      x = 1

      while x > 1

      OUTPUT This is an infinite loop;

    • 4

      Execute the code. When you do this, the statement "This is an infinite loop" will output to your computer terminal an infinite number of times (or until you stop the code from running).

Tips & Warnings

  • The steps above do not use any specific programming language, but rather use pseudocode. How the algorithm is implemented will depend on the programming language you choose to use.

  • Be sure you know how exit an infinite loop (e.g., from the command line, or a keyboard shortcut), as the loop may use an increasing amount of your computer's resources.

Related Searches:

References

  • Photo Credit Jupiterimages/Goodshoot/Getty Images

Comments

You May Also Like

  • What Is Stack Overflow?

    Consider the following example in pseudocode: function a {1. call function b. 2. call function c.} function b {1. call function c....

  • How to Use an Infinite Loop

    The patterns and methods you use in programming reflect your own approach to problem solving. Often, a programming requirement may potentially be...

  • How to Write a Pseudocode Code Script

    Pseudocode is the plain English equivalent of computer programming. In the planning stage of a script or program, before the actual code...

  • How to Make an Infinite Loop Program in Basic

    The Basic programming language is just that--basic. It uses commands and terms that make basic sense to just about anyone that would...

  • Define Infinite Loop

    In computer programming, a loop is a series of instructions a computer executes a fixed number of times. An infinite loop is...

  • How to Stop 0X000000EA Infinite Loop

    Uncheck the box labeled "Enable write combining." This will reduce the performance of your video card. If your computer stops crashing when...

  • How to Stop an Infinite Loop

    Loops are programming devices that specify that a section of a program is to be performed one or more times. Typically they...

Related Ads

Featured