For and Nested Loops

Learn about for loops and nested loops.

We'll cover the following

For loops

For loops are one of the most common types of loops and can be found in most programming languages. They take the following form:

for (initialization ; condition ; update) {
  // do something
}

Three things get set inside the parentheses:

  • The initialization code is run before the loop starts and is usually employed to initialize any variables that are used in the loop.
  • The condition has to be satisfied for the loop to continue.
  • The update code is what to do after each iteration of the loop, and it is typically used to update any values.

This process is illustrated in the following diagram.

Get hands-on with 1200+ tech skills courses.