For Each With Number On App Inventor

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



  1. How do you add those number arguments?

  2. Hello Sajal,
    I do not understand why LabelResult does not display each step for each value of the “Do” loop : 1, then 3, then 6, then 10, etc…
    Even if I introduce a delay in the loop, I only get the final result.
    How can I update a text field inside a “Do” loop ?
    Thank you,

    • Because we always override when we do “set LabelResult.Text to”. If you want to keep the old label value, you can add “LabelResult.Text” in the join block..

Submit a Comment

Your email address will not be published. Required fields are marked *