批量返回上一个标签("goto"命令) [英] Return to previous label in batch ('goto' command)

查看:92
本文介绍了批量返回上一个标签("goto"命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

@echo off
goto main

:main
echo Select:
echo 1) Goto label 1
echo 2) Goto label 2
set /p choice=
if %choice% == 1 goto label1
if %choice% == 2 goto label2

:label1
echo Will now direct you to label2
echo Press any key to go to label2
pause >nul

:label2 [PROBLEM HERE]
echo Type 'N' or 'E' and press Enter to go back to label1 or exit.
set /p choice2=
if %choice2% == N goto label1
if %choice2% == E exit

请忽略显示"goto main"的部分,我知道这不是必需的,但我已经习惯了.

Please ignore the part where it says 'goto main', I know it isn't necessary but I've got used to it.

问题在这里"表示我想让批处理返回到label1的部分,而无需实际键入代码以指定返回到先前的标签,因为有时我可能需要label1来完成一些工作,以便转到label2并工作另一件事,然后再次回到label1以继续其业务.

The "PROBLEM HERE" indicates the part where I want the batch to return to label1, without actually typing the code to specify to go back to previous label, as sometimes I might need label1 to work something to go to label2 and work another thing, then go back to label1 again to continue its business.

推荐答案

goto没有返回". 但是您可以call脚本的一部分:

goto has no "Return". But you can call a part of your script:

@echo off
echo main program
call :label1
echo main program
call :label2
echo main program

pause
exit /b

:label1
echo subroutine
goto :eof

echo never reached

:label2
echo sub two
goto :eof

这篇关于批量返回上一个标签("goto"命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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