Welcome!

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

SignUp Now!

FOR issues

Jun
12
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".
 
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".
 
FOR can't be used in @EXEC. Example:

Code:
echo %@exec[@for ^%A in (123) echo %A] > nul
returns "ECHO IS OFF".

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 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".

SWITCH is inherently a multiline construct, and FOR is inherently single-line. Use DO instead.
 
On Fri, 13 Jun 2008 16:29:59 -0500, you wrote:


>echo %@exec[@for ^%A in (123) echo %A] > nul
>---------
>returns "ECHO IS OFF".

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.
 
Charles Dye
I believe you need to double your percent signs here
Yeah, I'm wondering why I haven't tried this myself :)
SWITCH is inherently a multiline construct, and FOR is inherently single-line. Use DO instead.
Well IFF is another multiline construct, but it works inside FOR loop.

Anyway, I believe such things should be illustrated in Help.
 
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
 

Similar threads

Back
Top