在CMD中,直到按下Enter键才停止循环。

huangapple go评论74阅读模式
英文:

Loop stopping in cmd until Enter is pressed

问题

我提前道歉,因为这将是一个模糊的问题。我只希望有人有相同的经验并能帮助我。想象一个简单的脚本,其中包含以下简单的代码:

for i in range(100):
    print(i)

当我从终端(CMD)运行脚本时,偶尔会出现循环卡住的情况,但只要我在终端中按下回车键,它就会恢复工作,循环继续进行。我想强调的是,代码中没有类似于用户输入行的东西,导致循环暂停,直到按下键或类似的东西。而且,如果我在集成开发环境(IDE)中运行代码,就不会出现这种情况。这只会在CMD中发生,并且可能会在任何具有类似循环的脚本中发生。

英文:

I apologize in advance as this is going to be a vague question. I just hope someone has the same experience and can help me. Imagine a simple script that has this simple code in it:

for i in range(100):
    print(i)

When I run the script from the terminal (CMD), occasionally, the loop gets stuck but as soon as I press the Enter key in the terminal, it jumps back into working and the loop continues. I want to emphasize that there is nothing like a user input line in the code causing a pause in the loop until a key is pressed or anything like that in the code. Also, this never happens if I run the code inside an IDE. This only happens in CMD and in possibly in any script that has a loop like this.

答案1

得分: 0

当你点击命令提示符时,它会进入选择模式,你会看到一个白色的方块。你还会在命令提示符的顶部看到"select"(选择)的字样。这将暂停在命令提示符中运行的任何程序。

如果你按下回车键,它将退出选择模式并继续运行程序。

我相信这就是你遇到的问题。

英文:

When you click on the command prompt it goes into select mode, you will see a white square. You will also see at the top of the command prompt it will say select. This will pause anything running in the cmd.

在CMD中,直到按下Enter键才停止循环。

If you press enter that will get it out of select mode and will continue running the program

在CMD中,直到按下Enter键才停止循环。

I believe this is what your running into.

huangapple
  • 本文由 发表于 2023年8月9日 11:12:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定