How to create nested For loops
Example:
for i=1 to 2
for j=1 to 3
output would be / trying to get:
1-1
1-2
1-3
2-1
2-2
2-3
I tried this which works for the first For loop.
But it didn't work with the second For loop
How to create nested For loops
How to create nested For loops
Example:
for i=1 to 2
for j=1 to 3
output would be / trying to get:
1-1
1-2
1-3
2-1
2-2
2-3
I tried this which works for the first For loop.
But it didn't work with the second For loop
There is a general principle at play here, which is well understood in code languages but which seems not to be talked about in dataflow land.
In C / Java you have for( initializer ; stop_condition ; incrementer )
.
A for loop in Pd needs all of those, too.
Where to put the initializer? It needs to come before the loop proper ("until")... which is the other purpose of [t]: to sequence actions. Above [until], the [t f b] sends a bang first, which you use to set the [f] box -- initializing! (The given solution above is exactly how I teach it, fwiw.)
Then, after initializing, run the loop body. [until] receiving a number builds in its own stop condition.
I actually teach it as a three-step pattern -- initialize, loop body, finalize -- where the finalizer is sometimes not needed.
I know what I'm doing in code but it took me over a year to fully understand, in Pd, how and why to do this. That's a pedagogy problem (giving away fish rather than teaching how to fish).
hjh
Oops! Looks like something went wrong!