I did find a solution: use "if + 0 #cnt:" instead of "if #cnt:". Apparently dereferencing a variable with value 'undefined' produces a text string, but using it as an arithmetic operand treats it as 0.
When you place a hashtag in front of a variable name, it will return the value only if it recognizes the name, and it will otherwise return a string literal of the variable name with a hashtag in front of it. To get around this, use "if var cnt" instead.
When you place a hashtag in front of a variable name, it will return the value only if it recognizes the name, and it will otherwise return a string literal of the variable name with a hashtag in front of it. To get around this, use "if var cnt" instead.