Check if a variable exists
Peter Thomassen
info at peter-thomassen.de
Fri Aug 18 12:25:04 PDT 2006
Kirk McDonald schrieb am Freitag, 18. August 2006 21:14:
>> Is it possible to check if a variable exists, like PHP's isset()?
>
> Typically, you only ever have to ask when doing fairly complex template
> stuff; this is largely the point of a statically-typed language. Mind if
> I ask why you need to check for this?
I've got a for loop which contains an if statement checks something
depending on the counting loop var i. If true, some action producing a
temporary variable is taken.
After the for loop, I want to do further things if and only if the "if" tree
has been entered at least once. I cannot check that using i because that
has modified during the loop. Of course I could declare a bool in the "if"
tree and check for that, but I know that I will have the temporary variable
set, if the "if" tree has been entered. So, why not check for this?
> The answer, though, is this:
>
> static if (is(typeof(my_variable))) {
> // ...
> }
Thanks. What is the static keyword for?
Peter
More information about the Digitalmars-d-learn
mailing list