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

FOR loop with nested IF / IFF

Discussion in 'Support' started by Chris Wilcock, Sep 29, 2015.

  1. Chris Wilcock

    Joined:
    Aug 19, 2009
    Messages:
    17
    Likes Received:
    0
    Hello

    Prior to version 18, the following batch file snippet would display 1, 2, 3 on seperate lines. With version 18.32 however, only the first line is printed. If I change the condition to "1 EQ 1" then all three lines are printed.

    I've tried this with TCC-13 and all three lines are printed, as I would have expected.

    Is this the expected behaviour, or is this a regression in version 18?

    @ECHO OFF

    FOR %a IN (1 2 3) DO (
    ECHO %a

    IFF 1 EQ 0 THEN
    ECHO.
    ENDIFF
    )


    Thank you!

    Chris
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,353
    Likes Received:
    39
    I'm not sure what you're trying to do -- when would that test ever be true? -- but I wouldn't put a (multiline) IFF block inside a (single-line) FOR block. I'd substitute DO for the FOR.
     
  3. Chris Wilcock

    Joined:
    Aug 19, 2009
    Messages:
    17
    Likes Received:
    0
    Hello Charles

    It's not the actual batch file that I was executing. It's a stripped-down example to illustrate the problem, with a hard-coded test that's always false.

    Basically, if the FOR / DO loop contains an IF or IFF statement that evaluates to false, TCC seems to be bailing out of the rest of the loop without processing the other values in the loop.

    Chris
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,060
    Likes Received:
    30
    It's OK here.
    Code:
    v:\> type mline.btm
    @ECHO OFF
    
    FOR %a IN (1 2 3) DO (
    ECHO %a
    
    IFF 1 EQ 0 THEN
    ECHO.
    ENDIFF
    )
    
    v:\> mline.btm
    1
    2
    3
     
  5. Chris Wilcock

    Joined:
    Aug 19, 2009
    Messages:
    17
    Likes Received:
    0
    Hello Vince

    Which version of Take Command / TCC are you using? I am using version 18, and experiencing this problem. With version 13, the batch file works as expected.

    Chris
     
  6. Chris Wilcock

    Joined:
    Aug 19, 2009
    Messages:
    17
    Likes Received:
    0
    Hello Charles

    Apologies, I only replied to the first part of your comment yesterday. I will most likely adapt the batch file to use DO instead of FOR, but this is a previously-working script that I just happened to run for the first time with TC 18 the other day. I think I previously wrote it with either version 16 or 17, but as I commented previously it works as expected on version 13 too. I take your point about using IF / IFF in a FOR loop, but I was using parentheses to create a command group, as per a similar example in the online help for the FOR command.

    Chris
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,026
    Likes Received:
    84
    Not reproducible here (v18.00.32, x64, Windows 10).

    Are you using the same options in TCMD.INI?
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,060
    Likes Received:
    30
    I'm using version 18.31.
     
  9. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,353
    Likes Received:
    39
    I don't see the behavior you describe. I don't see it even if I change the IFF to IF and turn DuplicateBugs on, though I would expect it to fail in that case.

    You don't have any aliases for FOR or IF, do you? Of course not; that would be crazy. How about SETDOS?
     
  10. Chris Wilcock

    Joined:
    Aug 19, 2009
    Messages:
    17
    Likes Received:
    0
    Hello all

    I checked my TCMD.INI as per Rex's suggestion, and there was no setting for DuplicateBugs. Adding DuplicateBugs=No to the [4NT] section of this file has resolved the problem.

    Thanks very much to all of you for your help with this.

    Chris
     

Share This Page