break语句用于更改任何编程语言中循环内部的控制流, break语句通常用于循环结构中,并用于立即终止最内层的循环。
批处理脚本语言没有直接的" for"语句,该语句会中断,但是可以使用标签来实现。
以下是一个如何执行break语句的示例。
@echo off SET /A "index=1" SET /A "count=5" :while if %index% leq %count% ( if %index%==2 goto :Increment echo The value of index is %index% :Increment SET /A "index=index + 1" goto :while )
关于上述程序,需要注意的关键是添加了一个名为:Increment的标签,当index的值达到2时,无涯教程想跳过将其值回显到命令提示符的语句,而直接增加index的值即可。
上面的命令产生以下输出。
The value of index is 1 The value of index is 3 The value of index is 4 The value of index is 5
参考链接
https://www.learnfk.com/batch-script/batch-script-break-statement-implementation.html