Check if a variable exists

Peter Thomassen info at
Fri Aug 18 13:34:37 PDT 2006

Kirk McDonald schrieb am Freitag, 18. August 2006 21:39:
> Oh. Then you don't want this at all. Use the bool. :-) The reason is
> simple: if you declare the temporary before the for loop, then it will
> always exist after the for loop. If you declare the temporary inside the
> for loop, then it only has the scope of the for loop; it will cease to
> exist when the loop ends. Whichever way you do it, whether it exists or
> not after the for loop never varies.

This is not true, I tested it (using a while, not a for).

> Example 2: Declare inside the loop
> for (;;) {
>      int temp;
>      // stuff
> }
> // temp doesn't exist anymore; its scope ended

See above.

> Static if is analogous to #if/#endif in the C preprocessor. It does not
> apply here, so nevermind what I told you. :-)

Mh ... I only know PHP :-)

More information about the Digitalmars-d-learn mailing list