Select Page

For Each with number is used for doing something a number of times for a given range. There are four slots/arguments in that block which are given. First by default there’s a number slot which is the counter telling you the current iteration/loop number. You can change the name of the number variable to whatever you prefer. In the from slot, we specify the starting value for the range of iterations; in to slot, we specify the last value; and the by slot where we specify after each loop/iteration by how much it should increment or decrement the value of loop variable (number). We are going to write an app that will calculate sum from 1 to a given number.

In the screenshot below, you specify a number in the text box and then hit Calculate button. The app will give you the sum.

Look at the comments in the screenshot below. It should be easy for you to understand-

Download the project source of this tutorial – ForEachNumber