(MAI) Iteration Lesson
Iteration
Iteration is another essential programming concept. Iteration is used to search through and manipulate list and repeat blocks of code.
There are two types of blocks for iteration in App Inventor:
while
A while loop will repeat any condition while it is true. It is a more general type of loop that can be used to iterate anything. The while-do blocks require a conditional test just like if statements.
A while loop has a test which is boolean expression that will evaluate to true or false.
Examine the code below. What does it do? On the left is the App Inventor code. On the right is the same code in Java. Click answer to self-check.
Answer
foreach
The foreach block is used to process a list. It applies a set of functions to each element of the list. Analyze the code below. This code will print the contents of a list.
Searching for Numbers and Strings
The foreach is used to search through a list to find an element in the list. Go through the learning object to analyze the code for searching for a number and searching for a string.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION