Loops can be created to executed a block of code for a fixed number of times. Alternatively, loops can be created to repetitively execute a block of code until a Boolean condition changes state.
For instance, the loop may continue until a condition changes from false to true, or from true to false. In this case, the block o code being executed must update the condition being tested in order for the loop to terminate at some point. If the test condition is not modified somehow within the loop, the loop will never terminate. This created a programming bug known as an infinite loop.
- Using a for statement
- using a while statement
- Using a do-while statement