programming loops in Max
Been trying to review types of looping methods in Max such as for, while, do-while (entry-controlled, exit-controlled) and generally I see [vexpr @scalarmode 1] or [js] used in these situations. The [GenExpr] documentation also has a header on "Branching and Looping".
Beyond the above I'm guessing the usual way to achieve this in vanilla Max is a combo of [coll] [counter] [uzi] and [zl], or perhaps some cold-inlet recursion of the [+] to accumulate – I just wondered if people have other methods I'm overlooking? or would be willing to share the most pragmatic approaches to looping they know of?
would appreciate the insights
i definitely go with uzi if i need to spit out a lot of numbers at once. for things that loop over time, stuff like this works:
You can do a lot with [gate] and [trigger], two fundamental objects in Max.
thankyou both, very useful and not implementations I've seen previously.
"for"
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P hidden newex 119 333 108 196617 bgcolor 150 250 50;
#P newex 268 154 75 196617 110.defarg 1;
#P newex 366 104 59 196617 loadbang;
#N comlet result;
#P outlet 42 333 15 0;
#P newex 366 241 59 196617 i 2;
#P newex 42 154 59 196617 t 2 b 1 b;
#P newex 42 259 59 196617 gate 2;
#N comlet insert in \, from process;
#P inlet 478 225 15 0;
#N comlet insert out \, to process;
#P outlet 478 277 15 0;
#P newex 181 241 59 196617 zl reg;
#N vpatcher 41 149 441 449;
#P window setfont "Sans Serif" 9.;
#P newex 86 98 50 196617 t b;
#P outlet 86 134 15 0;
#P outlet 173 134 15 0;
#P inlet 173 82 15 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 0 0 1 0;
#P pop;
#P newobj 42 114 59 196617 p tbd;
#P newex 268 122 59 196617 i #1;
#P newex 181 172 59 196617 uzi;
#N comlet number of iterations i;
#P inlet 230 41 15 0;
#P inlet 42 41 15 0;
#P connect 8 1 6 0;
#P connect 12 0 3 0;
#P connect 12 0 10 0;
#P connect 3 0 13 0;
#P connect 4 1 5 1;
#P connect 7 0 5 1;
#P connect 1 0 2 1;
#P connect 13 0 2 1;
#P connect 2 0 5 0;
#P connect 9 1 5 0;
#P connect 9 3 2 0;
#P connect 5 0 8 1;
#P connect 8 0 11 0;
#P connect 9 0 8 0;
#P connect 10 0 8 0;
#P connect 9 2 8 0;
#P connect 4 0 9 0;
#P connect 0 0 4 0;
#P window clipboard copycount 15;
connect like that:
[110.iterate-insert] X [youralgorithm]
thanks Roman, sorry but what is [110.defarg 1] ?
if $i1==0 then 1 else $i1
internal default when no argument is given. kinda pointless for this patch, in many others not.
and i $1 should read i #1
the forum always corrupts that (and i forgot to correct manually)
so like below?
what does each inlet and outlet denote? sorry if it's obvious, I'm not seeing it clearly.

yes looks right. works?

oh, the inlet descriptions also didnt survive. :)
#N comlet insert in \, from process;
nice, thanks for explaining!
With this subpatcher, you can nest as many loops as you want, going in either direction.
Instructions inside. It is fresh from the oven and seems to work fine, but if anybody finds an anomaly, I would appreciate hearing of it.