Evaluating loop variables
Let’s take a closer look at the code for Figure 10.8. Could there possibly be even more variable options to adjust? How about iterating colors and interconnecting between loop repetitions? Yes, you can achieve this within the same loop. So, let’s look at further advanced \foreach
options – at first, some syntax with short examples, and then a more extended example.
Counting loop repetitions
A \foreach
value list can contain alphanumeric values and patterns to be iterated through and utilized within the loop commands. However, we may want to use values based on their position in the list, such as using the (\j,0)
coordinate at position j
in the iterative order of list values.
This is where the count
option comes into play. Let’s say we have \i
as the loop variable iterating through letters. We introduce the \j
counter as follows:
\foreach \i [count=\j] in {A,...,Z} {commands};
Now, while \i
iterates from A
to Z
, \j...