Programmers use a for loop to run a section of code repeatedly for a predetermined number of times. Typically, it has three components:
- Initialization: The loop counter variable is given a starting value in this section. Often, this is carried out prior to the loop’s execution.
- Condition: Before each iteration of the loop in this section, a condition is checked. The loop keeps running if the condition is true. The loop ends if the condition is false.
- Decrement: At each loop iteration in this section, the loop counter variable is either increased or decreased. By doing this, the loop will run the appropriate amount of times.
example
for (initialization; condition; increment/decrement) {
}
Leave a Reply
You must be logged in to post a comment.