For Loops

Let's take a look at the key features of for loops.

The age-old for loop has become a staple in the world of programming. It allows us to specify a range of numbers over which we want our loop to run.

It also has another component called the iterator. The iterator is responsible for keeping track of the iterations. Initially, its value is the start of the loop range, which changes with each iteration.

The return type of a for loop is expected by the compiler to be unit. Hence, it is not a good practice to return things from the for loop to the program outside its scope.

The Structure

Below, we can find the basic template of a for loop.

Get hands-on with 1400+ tech skills courses.