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

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

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-2.html
匿名

发表评论

匿名网友

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

确定