Use ksh. ksh has shell builtin's to check for those conditions.
From man ksh under the Parameter sub-heading.
Modifiers can be applied to the ${name} form of parameter substitution:
${name:-word}
if name is set and not null, it is substituted, otherwise word
is substituted.
${name:+word}
if name is set and not null, word is substituted, otherwise
nothing is substituted.
${name:=word}
if name is set and not null, it is substituted, otherwise it is
assigned word and the resulting value of name is substituted.
${name:?word}
if name is set and not null, it is substituted, otherwise word
is printed on standard error (preceded by name:) and an error
occurs (normally causing termination of a shell script, function
or .-script). If word is omitted the string ?parameter null or
not set? is used instead.
In the above modifiers, the : can be omitted, in which case the condi-
tions only depend on name being set (as opposed to set and not null).
If word is needed, parameter, command, arithmetic and tilde substitu-
tion are performed on it; if word is not needed, it is not evaluated.
if VAR is already set (and not null), will be reset with its own value; else will be set to "default_value". In your case, you can put 0 for this value.
Another less elegant but maybe more clear way is: