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

FOR issues

Discussion in 'Support' started by Raistlin, Jun 13, 2008.

  1. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    1. FOR can't be used in @EXEC. Example:
      Code:
      echo %@exec[@for ^%A in (123) echo %A] > nul
      returns "ECHO IS OFF".
    2. SWITCH works incorrectly from inside FOR loop: executing
      Code:
      for %A in (123) (
       switch a
       case a
        echos aaa
       case f
        echo fff
       endswitch
      )
      
      returns "aaafff".
     
  2. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    3. It seems that RETURN is not allowed in nested FOR loops: executing
    Code:
    gosub aaa
    echo %bbb
    quit
    :aaa
    for %A in (123) (
     for %B in (345) (
      return
     )
     set bbb=ccc
    )
    displays "ccc".
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,272
    Likes Received:
    38
    I believe you need to double your percent signs here:

    Code:
    echo. %@exec[@for %%A in ( 123 ) echo %%A]
    
    (The period after ECHO is a rather nasty way of preventing the "ECHO is OFF" message.)

    SWITCH is inherently a multiline construct, and FOR is inherently single-line. Use DO instead.
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,716
    Likes Received:
    29
    On Fri, 13 Jun 2008 16:29:59 -0500, you wrote:


    v:\> echo %@exec[for %%A in (123) echo %%A]
    123
    0

    v:\> echo %@exec[@for %%A in (123) echo %%A]
    123
    ECHO is OFF

    as expected.
     
  5. Raistlin

    Joined:
    Jun 13, 2008
    Messages:
    12
    Likes Received:
    0
    Charles Dye
    Yeah, I'm wondering why I haven't tried this myself :)
    Well IFF is another multiline construct, but it works inside FOR loop.

    Anyway, I believe such things should be illustrated in Help.
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    Raistlin wrote:
    | *Charles Dye*
    | ---Quote---
    | I believe you need to double your percent signs here
    | ---End Quote---
    | Yeah, I'm wondering why I haven't tried this myself :)
    |
    | ---Quote---
    | SWITCH is inherently a multiline construct, and FOR is inherently
    | single-line. Use DO instead. ---End Quote---
    | Well IFF is another multiline construct, but it works inside FOR loop.

    Technically, DO and SWITCH are multiline commands; IFF is a multiple
    command.

    |
    | Anyway, I believe such things should be illustrated in Help.

    Agreed. Some elements are. Impossible to illustrate all possible variations.
    SWITCH is documented to perform its actions "in a batch file". The existence
    of limitations in using a command group in the DO clause of FOR is also
    documented.
    --
    Steve
     

Share This Page