FOR issues

Jun 13, 2008
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".
 
Jun 13, 2008
12
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".
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,425
85
Albuquerque, NM
prospero.unm.edu
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.
 
May 20, 2008
11,292
95
Syracuse, NY, USA
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.
 
Jun 13, 2008
12
0
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.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
Thread starter Title Forum Replies Date
S Issues with version v26.02.42 x64 Support 0
Jay Sage Issues With TCMD File Explorer Support 0
samintz ANSI issues Support 3
KarstenG PSUBST issues with Win10 2004 ? Support 4
Joe Caverly @HISTORY issues Support 4
Peter Murschall V26-Issues in the BDEBUGGER ! Support 11
J Moving from TCC v22 to TCMD v24 issues Support 3
A Downloads page issues Support 1
T @select and @selectarray issues Support 2
M A list of issues .. Support 17
Robert Kantor 20.00.25 Issues Support 6
T tchelp.exe issues Support 2
E Fixed Issues with DEDUPE Support 0
H New Install; Everything setup issues Support 9
Jay Sage WAD Issues with LOG Command Support 4
cgunhouse Registry Issues Support 8
S Take Command issues at high resolution Support 9
samintz WAD @format has issues in v18.00.14 Support 10
Charles Dye Assorted trivial issues Support 5
jbanaszczyk bdebugger issues Support 4
JohnQSmith Fixed Copying with regex (several issues) Support 7
S Documentation HELP issues Support 8
nikbackm Fixed v15: VIEW - encoding and CSV issues Support 9
Dan Glynhampton Documentation Minor issues with HELP Support 0
B Two Issues With TIMER Command In V14 Support 10
M @FileRead from a device issues... Support 6
R A couple of minor issues with new forum. Support 4
Stefano Piccardi 13.0.31 2 MKLINK TCC vs CMD issues Support 2
S FORUM subscription issues Support 3
M More SafeChars type issues... Support 4
dolmen Compatibility issues with cmd.exe Support 1
S HELP issues Support 9
nikbackm unzip issues in v12 Support 12
samintz bdebugger issues Support 55
vefatica Installer issues Support 7
williamleara Specifying path to TCMD.INI causes issues Support 8
S @SERVER issues Support 1
S @enumservers and @enumshares issues Support 1
S Forum issues Support 4
S FTP issues with 11.0 Support 9
jcalcote Apache Maven startup batch file issues Support 3
Jay Sage TCMD11 Toolbar Issues Support 2
H ZIP/UNZIP issues Support 4
J V10 "Configure tab toolbar" issues Support 3
J weird issues in TC10.00.55 Support 4
S Minor HELP issues Support 1
P bdebugger / ide issues Support 1
Fross Continue to have issues layout in v10 Support 11
J TCMD 10 issues Support 2

Similar threads