在Windows批处理文件中,如何同时循环2套 [英] in windows batch file, how to loop 2 sets simultaneously

查看:102
本文介绍了在Windows批处理文件中,如何同时循环2套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows批处理文件中,如果有两组,如何同时循环(而不是嵌套循环)?

In windows batch file, if I have two sets, how do I loop them simultaneously(not nested loop)?

SET A =(1,2,3)SET B =(A,B,C)

SET A=(1,2,3) SET B=(A,B,C)

循环(1,A), (2,B), (3,C)对?

推荐答案

@echo off
set "A=1,2,3"
set "B=A,B,C"
setlocal enableDelayedExpansion
set f1=0
set f2=0
for %%Z in (%A%) do (
   set /a f1=f1+1
   for %%Y in (%B%) do (
      set /a f2=f2+1
      if  !f1! == !f2! (
         echo [%%Z,%%Y]        
      )
   )
   set f2=0  
)

没有嵌套就无法完成.我更喜欢使用方括号,以避免与普通方括号混淆.

Cannot be done without some nesting. I preferred rectangular brackets to avoid escaping with the normal ones.

这篇关于在Windows批处理文件中,如何同时循环2套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆