To CodyVa:
You cant''t compare a variable to a value if it is not declared and as menationed earlier you can''t access a variable outside you''re scope but the global scope.
Your code:
if (x != null) { ++x;} //if x is declared increment
else {int x = 0;} //if not declare it
For the compiler, this is like: compare the global variable x to zero and increment its value if it is so.
else declare a new variable x. Because the new variable is declared in a block, it is only valid and accesible in the block itself.
I think you can make it with a static variable, but then you should be aware to decrement the variable again when returning from the function. Because you never would be able to call the function again.
Another approach would be to use a function like this:
void func (int maxiterations)
{
if ( maxiterations > 0 )
if (somethinggoeswrong)
func(maxiterations-1);
}
Hope this helps