本文介绍了"计数器"在批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个批处理文件,将通过1每次循环时间增加一个变量,然后检查变量等于5,如果它不是,它再次循环。我知道可能有这个while循环,但我不知道该怎么做,而我只是享受现在学习的乐趣批次

I'm trying to make a Batch file that will increment a variable by 1 each time it loops, and then check if the variable is equal to 5, and if it isn't, it loops again. I know there's probably a while loop for this, but I didn't know how to do that, and I'm just enjoying learning Batch for fun right now

这里的code,它不工作应该的方式,它只是显示一个0:再没有别的。所以,我怎么会去修复它?我有一种感觉,我设置和增加变量错了,也许是困惑的2 if语句? (它有一个else如果....?)反正,感谢帮助

Here's the code, it doesn't work the way it should, it just displays a 0: and then does nothing else. So how would I go about fixing it? I have a feeling I'm setting and incrementing the variable wrong, and maybe it's confused about the 2 if statements? (Does it have an else if....?) Anyways, thanks for the help

@echo off
set /p i=0:
goto A

:A
set /p i=i+1:
if i != 5 goto C
if i == 5 goto B

:C
echo Test :D

:B
pause>nul

请注意:我不知道很多料和我不是一个职业球员,但我喜欢学习,我只是在做这个以供将来参考,因为我喜欢它。所以,这code可能不是很好,但我想知道我怎么能做到这一点。

Note: I don't know a lot of Batch and I'm not a pro, but I like to learn and I'm just doing this for future reference, and because I enjoy it. So, this code probably isn't good, but I want to know how I can accomplish this.

推荐答案

这是模拟你试图完成while循环的一种方式。只有一个转到需要:

This is a way to simulate the while loop you are trying to accomplish. Only one goto is needed:

@echo off
set /a x=0
:while
if %x% lss 5 (
  echo %x%
  pause>nul
  set /a x+=1
  goto :while
)
echo Test :D

这篇关于"计数器"在批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:02