Welcome!

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

SignUp Now!

Odd IF behavior

May
366
4
This seems odd to me and I wanted to find out why. When I run this, the set line does not fire if the if statement above it is false.

If I use iff/endiff instead it works, or if I remove the FOR statement it works, but I would think that it should work as written.

Code:
for /L %i in (1,1,1) do (
        if defined DEBUG then echo THIS IS A TEST
        set ___DEBUGTEST=test
)
What am I missing?

Michael
 
This seems odd to me and I wanted to find out why. When I run this, the set line does not fire if the if statement above it is false.

If I use iff/endiff instead it works, or if I remove the FOR statement it works, but I would think that it should work as written.

Code:
for /L %i in (1,1,1) do (
        if defined DEBUG then echo THIS IS A TEST
        set ___DEBUGTEST=test
)
What am I missing?

Michael

FOR is inherently a single-line command, so all of your lines above are contatenated into one. The setting "Duplicate CMD.EXE bugs" (near the bottom of the right column on the first page of the OPTION dialog) applies....

(Also note that the THEN keyword only works with IFF, not IF.)
 
A FOR statement is not really a multiline statement. It is a single
statement. So the command for your FOR is effectively

if defined DEBUG then echo THIS IS A TEST & set ___DEBUGTEST=test

You are always better off using a DO loop when you have multiple lines.

-Scott

frossm <> wrote on 01/22/2009 03:40:27 PM:


> This seems odd to me and I wanted to find out why. When I run this,
> the set line does not fire if the if statement above it is false.
>
> If I use iff/endiff instead it works, or if I remove the FOR
> statement it works, but I would think that it should work as written.
>
>
> Code:
> ---------
> for /L %i in (1,1,1) do (
> if defined DEBUG then echo THIS IS A TEST
> set ___DEBUGTEST=test
> )
> ---------
> What am I missing?
>
> Michael
>
>
>
>
 
Thanks Scott and Charles. I will switch the bigger btm over to a do
statement.

It would also make it easier to debug as well!

Much appreciated.

Michael




On Jan 22, 2009, at 3:14 PM, samintz <> wrote:


> A FOR statement is not really a multiline statement. It is a single
> statement. So the command for your FOR is effectively
>
> if defined DEBUG then echo THIS IS A TEST & set ___DEBUGTEST=test
>
> You are always better off using a DO loop when you have multiple
> lines.
>
> -Scott
>
> frossm <> wrote on 01/22/2009 03:40:27 PM:
>
>
>
> ---Quote---
>> This seems odd to me and I wanted to find out why. When I run this,
>> the set line does not fire if the if statement above it is false.
>>
>> If I use iff/endiff instead it works, or if I remove the FOR
>> statement it works, but I would think that it should work as written.
>>
>>
>> Code:
>> ---------
>> for /L %i in (1,1,1) do (
>> if defined DEBUG then echo THIS IS A TEST
>> set ___DEBUGTEST=test
>> )
>> ---------
>> What am I missing?
>>
>> Michael
>>
>>
>>
>>
> ---End Quote---
>
>
>
 

Similar threads

D
Replies
2
Views
2K
drrob1
D
Back
Top