1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Odd IF behavior

Discussion in 'Support' started by Fross, Jan 22, 2009.

  1. Fross

    Joined:
    May 30, 2008
    Messages:
    224
    Likes Received:
    1
    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
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    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.)
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,178
    Likes Received:
    11
    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:


     
  4. Fross

    Joined:
    May 30, 2008
    Messages:
    224
    Likes Received:
    1
    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:


     

Share This Page