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
How do you add those number arguments?
Look at the Result variable.
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..
Hello Mr Sajal. can you teach me, how about showing the number in the MIT app inventor, if there is 1 and 2 then the result is two number, or in the textbox the input is “Textbox1” and the result can show 1 uppercase, 6 lowercase, and 1 number.
Thank you very much