### If/Then vs. Logic

Hello everyone,

From what I understand, "if" and "expr", while easier to comprehend for a novice programmer, are an inefficient way to check and compare values. However, most of Max’s logic objects are limited to only comparing two numbers.

For example, I have the following statement, "if $i1 + $i2 + $i3 + $i4 + $i5 + $i6 + $i7 + $i8 + $i9 == 0 then bang". All I really want to do is check 9 toggles, bang if they’re all off. It seems like I should be able to use && for something like this, but it will only compare two numbers. I even thought about using coll or some sort of list operation, but that seems like it would be unnecessarily complicated.

Anyone know the best (most efficient) way to perform operations like this?

Thanks in advance for your help!

In this particular situation another logic is possible, putting the values of all the toggles in a list and summing the result. If you have 9 times a 1 (toggle on) than the sum is 9. This you can feed to a selecting procedure…

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 704.3ocwX9saaBCEF+Z3o.w0YU9OXio2smiooJf3k5Vvf.mtrV028gMgDZGo 0TxLJRNA6CG888i3is4EeuvrpC71vfaC9Qfm2K9ddltzc3c7ZuvxzC4Eoslv ByqJK4RU3l9wT7CJS+7hV9sC8J2WJjEbk4VfG6Tr0DXU1CeCQFh7WURkLsja F56MhzhQ4nZuZHIfQw2Jd1DODbyP20op76Exc20vyU81AljzMb.hX9BizsP1 MffepukW880MaVnqSKJBpj16arC7MlL12wKx2Y6UpJo01CNsIFBU2kPxyqJp ZNJVs5.mZfZYNJXtR8mZdengYoxcgmFNqKSOZWll.RHLdDjPfgVG.IXxbgD3 FLgxnXs0X3DDjp+EFPXLzhXl8Idp+mEytdHTx+cGa9moWs7hfjIAKZBvFO2I WnODaaBBOitYL+6HWPri0cHKX92E3xyEAs6KsFLzqFXVJT.QFnjrnhRW.J0o OF.d+mIYTxDLZ1qHAuHi957Ax5KdgVVUaU0tcEbaKHcZBVcZSmuU7l63xzrB 930erz6ht0HOWzng21snYpRTIG40nDyZwnn2Tx9iJ0fo87.dMJ0LO3.AtlNT xboSDX0nCz0zouzwbnCLZsnC00vAB6gCxV3fXz0BNwNFNXVzbgS+NaVC3vbM bHr4Bm9MPuFvg3Z3fAyEN.xZAmHWCG.clvYXqNq.bv+2fyD1jf9baZRPn93d u6cvXRnt+2581p8M4CJX3LOAvS5XKuUIjlmQiBRer7fyOStWrcKWN1xaEsZJ X.EXxmByROfOQO5S.6J8PsQOwtSODazC0Y5IwF4n0LyM3AXqdhcidf1pGpSz C0V4PbhbhsUNQNQNLakC1IxgXqbPNQNQ1JGnSjC1V47UJD1utZZc8S7l1i4z njtcO7P+a+jtwboP1eoIigM7mDCwS70Y6U++BHqZC6B -----------end_max5_patcher-----------

Rock and roll! I had a feeling that some sort of list would be the way to go. I was actually checking to see if the toggles were all off, so changing sel 9 to sel 0 returns the bang I’m looking for.

Cheers! :)

You might also want to look into [vexpr], the list-savvy version of [expr].

to find out if the sum of al is zero, multiplying them using [accum] should be enough.

Forums > MaxMSP