By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Conditional expressions


Am I the only one who finds this an odd design?

I mean, I know the expression is designed to return the exit status of the logical expression, and that 1==1 is very very true, but ...

Am I missing a hidden gem?
Last edited:
I asked about the odd return from %[[ ]] when it was first added. Rex said that he was thinking in terms of return codes: 0 generally means success, and nonzero is failure.

And indeed the documentation for %[[ ]] mentions "exit status", though I didn't connect that with ERRORLEVELs.
Thank you for your reply, Charles.
Rex said that he was thinking in terms of return codes: 0 generally means success, and nonzero is failure.
Yes, he wrote that in the help-file. And I got that.

We will come to love it with the years?

It is very confusing - that's what it is.
I wonder how many users are actually using it.

Okay, I think I feel a suggestion coming up...
It seems wrong to me.
v:\> echo %@if[%[[1==1]],1,2]

v:\> echo %@if[1==1,1,2]

To put it another way, %[[condition]] seems to have the same truth value as (NOT condition).

Where is %[[...]] documented?
Where is it documented that @IF accepts an integer as "condition" (and where is it's evaluation documented)?
I have not been able to find it in the usual places of the helpfile. It is mentioned in the "What's new" for version 23.

Perhaps, if this feature has gone unnoticed because it wasn't documented properly, it's not too late to repair this.
I found it there too. IMHO, if it's going to stay as it is (TRUE -> 0) it should remain poorly documented. But in any case, what's it for? I can't think of a use for it that can't be done more easily otherwise.
Did you notice that all nonsensical conditional expressions give 0 (are true)?

v:\> echo %[[foo]] %[[5+3]] %[[c:\windows]] %[[0]] %[[1]]
0 0 0 0 0
I don't need a need.
You told me there was something new. (in the help)
I went ahead and checked it out. (not much documentation)
I tried to envision what the Almighty might have been thinking of when going out of his way to deliver this gem (we did not know about any corporate account).
I was hoping for an elegant way to pre-calculate a boolean value without if / iff and use it multiple times in subsequent tests without having to repeat the boolean expression.
And then the only the @IF appeared to be able to test that boolean, (if's need '%bValue==1' which kinda spoils it),
and then the expected return seemed reversed.
Sure. frustrating. What else?

Are you really going to blame me for misunderstanding?
If so, are you really surprised that I went ahead and experimented without asking ?
If you want me to change existing behavior (and break existing batch files & aliases), then you need an exceptionally compelling argument.

"I saw it in the What's New (from a couple of years ago) and though I don't have a need for it I didn't like the way it was implemented" doesn't rise to the level of compelling.

Similar threads