Chapter 11 Iteration
Every time some operations have to be repeated, a loop may come in handy. Loops are good for:
- Doing something for every element of an object;
- Doing something until the processed data runs out;
- Doing something for every file in a folder;
- Doing something that can fail, until it succeeds;
- Iterating a calculation until it reaches convergence.
Here, we will learn the following types of iteration statements:
for() {}
while() {}
repeat {}
We will also dive into the apply()
family functions, which are interesting function-based alternatives to for() {}
loops.
We will finally learn about two special statements that allow us to control iterations:
break
next