Loops are useful when you repeatedly want to run the same code, but with a different value each time it runs. There are numerous types of loops, however, “for loops” are used to loop through a block of code a number of times.
The for loop has the following syntax, or format:
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
Statement 1 is executed one time before the execution of the code block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed every time after the code block has been executed.
Leave a Reply
You must be logged in to post a comment.