windows bat无限循环的实现

一个简单易行的方式:

:loop 
goto loop

参考网上文档:
Using the goto command within a batch allows a user to loop or restart a batch file after it has been completed. Below are some examples of how this command can be used. This page was created with the easiest, but not necessarily recommended solution first, to the most difficult solution but recommended method last.

@echo off
cls
:start
echo This is a loop
goto start

In this first example, the computer will print “This is a loop” over and over until you terminate the file. To cancel this example press: CTRL + C.

@echo off
cls
:start
echo This is a loop
pause
goto start

Next, adding the pause statement before the goto line will prompt the user to press any key before looping the batch file. Adding pause allows the user to run the batch when they’re ready.

@echo off
cls
:start
echo This is a loop
set choice=
set /p choice="Do you want to restart? Press 'y' and enter for Yes: "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto start

Finally, in this last example and most recommend method, the user would be prompted if they want to rerun the batch file. Pressing “y” would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file. This example is for Windows 2000, XP, and later users if you’re running earlier Windows 98 or earlier you’d need to use the choice command.

参考文档:http://www.computerhope.com/issues/ch001050.ht

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值