As a programmer learning how to write math-notation, I want to be able to exit when some function inside the Sigma summation has reached a particular value, but keep the value that the Sigma has computed. In programming this is easy, but not as math notation (unless I have missed something).
Say I have $x\in\mathbb{N}$ as bitstring: $x = 1100100110110101_2$ $(=51637_{10})$ and I check each pair from right to left: $01$ $01$ $11$ $10$ $01$ $10$ $00$ $11$ using $\pmod 4$ I need to make a "counter" function, such that when the pair reaches one of the bitvalues: $11$, $10$ or $00$ the counter stops else increases by $1$.
In decimal this would be equivalent of saying that when $51637 \pmod 4$ equals: $3$,$2$ or $0$ the counter should stop else add $1$ and continue.
And on the next iteration we divide $51637$ by $4$ to get $12909$ so: $12909 \pmod 4$ equals: $3$,$2$ or 0 counter should stop else add $1$ and continue. and iterate this procedure until $x = 0$.
So we have the function:
$S(n)=\begin{cases} 0 & n\equiv 0\pmod4 \\ 1 & n\equiv 1\pmod4\\ 0 & n\equiv 2\pmod4\\ 0 & n\equiv 3\pmod4\end{cases} $
The iterative procedure should stop at the first instance of one of these zeros, but keep the value that $S(n)$ has computed along the way. $S(n)$ has a drawback with this, it does not return after hitting the case: zero. For me it feels like a general barrier (if one could call it that) in all functions though. Or could one use two-dimensional functions to overcome this?
There is no exit-case in sigma-symbol as far as i can tell. The problem is that the "counter" function continues after reaching $3$,$2$ or $0$, but i don't want that.
Are there any solutions to this problem? I also dont know if capital pi notation can be used in the solution or not?
Example
If $c$ is the bitstring length divided by $2$, and $n=51637$, an example would be: $$Z(n)=\sum_{i=0}^{c-1} \frac{S(n)}{4^i}$$ $Z(n)$ should return the value $3$. But it does not because Sigma has to finish.
Don Fuchs solution seems to give the right answer, if this table is correct (See image below):

Your idea to use a product isn't too bad; I would try $$ Z(n)=\sum_{i=0}^\infty\left[S\left(\frac{n}{4^i}\right)\prod_{j=0}^iS\left(\frac{n}{4^j}\right)\right]. $$ With the first $i$ such that $S(n/4^i)$ equals $0$ the inner product contains a $0$ factor and therefore is $0$, and remains $0$ even for higher indices $k$ where $S(n/4^k)$ might equal $1$ (it "has a memory").
Also note the divisor $4^i$ dividing the argument of $S$, not $S(n)$ itself, to get your desired iterative structure (if I got you right there).