title: How to have a hybrid static function variable?
body: <p>If I understand correctly, declaring a variable static in a function preserves its value across iterations of that function.  What if I want to preserve a variable's value conditionally?  For example, say I have two functions, <code>foo()</code> and <code>bar()</code>.  Let's say that every call to <code>foo()</code> results in 5 calls to <code>bar()</code>.  I have a static variable <code>x</code> in <code>bar()</code> that is preserved.  What do I do if I want the value of <code>x</code> to be preserved across the 5 calls from <code>foo()</code>, but then when <code>foo()</code> ends the value should be reset?  I'm looking for an explanation as well as example code.</p>