问题标签 [while-loop]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
1352 浏览

vb.net - Canceling a While loop prematurely

I'm using a While loop that loops a certain number of cycles (1-576) based on a value entered by a user. It's activated by the user clicking a "Start" button, But I would like it to be able to be canceled using, preferably, the "Escape" key.

However, when the loop is going I can't get the program to recognize any keypresses.

My Loop

While the loop is running my keypresses don't register, otherwise they register fine.

0 投票
14 回答
828505 浏览

bash - Bash 中单行 while 循环的语法

我无法想出正确的分号和/或大括号组合。我想这样做,但作为命令行的单行代码:

0 投票
3 回答
460 浏览

php - 如何用 PHP 打印出问题的答案?

如何将以下示例数据与 aforeachwhile循环一起使用?

我通过运行得到以下示例数据

样本数据

但是,我不确定这是否是提取数据的最佳方法,因为我不确定如何从上述格式中提取数据。我没有成功运行:

1.

#1 是我从资源中获取数据的唯一方法。我已经尝试了#2方式不成功。

2.

这种方式没有提供任何输出,这令人惊讶,因为示例数据显示每个答案都有相应的字段。

0 投票
4 回答
1301 浏览

python - 帮助 Python while 循环行为

我有一个脚本,它使用一个简单的 while 循环来显示一个进度条,但它似乎没有像我预期的那样工作:

它似乎在“p.render ...”处循环,并且不会返回“print 'Processing %d of %d ...'”。

更新:我很抱歉。似乎 ProgressBar.render() 在渲染进度条时删除了“print 'Processing...”的输出。进度条来自http://nadiana.com/animated-terminal-progress-bar-in-python

0 投票
34 回答
132801 浏览

javascript - Are loops really faster in reverse?

I've heard this quite a few times. Are JavaScript loops really faster when counting backward? If so, why? I've seen a few test suite examples showing that reversed loops are quicker, but I can't find any explanation as to why!

I'm assuming it's because the loop no longer has to evaluate a property each time it checks to see if it's finished and it just checks against the final numeric value.

I.e.

0 投票
7 回答
13558 浏览

vb.net - 如何在while循环中限制CPU使用率

你如何限制while循环的CPU?

在这种情况下,while 循环内的代码:

但是现在,问题来了。此循环允许 while 循环每秒运行一次,并且waitsub 会导致此延迟,因为它应该。

如何限制这占用的 CPU?出于某种原因,我的任务管理器说运行这个简单的任务需要 50 个 CPU,但它可能需要不超过 1 或 2 个。虽然经理说它需要那么多 CPU,但我的计算机速度并没有受到影响所有,考虑到它是一台使用了两年的笔记本电脑,这很奇怪。

我不希望任何用户对此感到害怕,但要知道这些天人们的状况......

无论如何,语言是vb.net。有人可以帮帮我吗?

谢谢!

编辑:澄清一下,该代码不在while循环本身内,而是对子例程的调用,即wait(1000)

0 投票
17 回答
6186 浏览

c++ - 有什么理由在 C++ 中用 for(;condition;) 替换 while(condition)?

好像

完全等价于

有什么理由使用后者而不是前者?

0 投票
4 回答
2454 浏览

java - Java while循环不循环

我的摇摆界面中有以下按钮

调用 step1();

问题似乎是 step1() 中最外层的 while 循环。它应该一直运行直到满足所有条件,但它只是在一次迭代后停止,我不知道为什么。如果我删除外部 while 循环 step1() 完全按照它应该通过多次按下按钮的每个步骤进行。帮助!

0 投票
6 回答
2862 浏览

php - PHP四舍五入,添加十进制数字

我正在使用一个简单的循环来回显一些数字

但是 5.00 显示为 5 而 4.50 显示为 4.5

我如何让这个脚本显示 5.00、4.00、3.00、3.50

还为标题道歉,我不知道如何解释!

谢谢

0 投票
4 回答
55696 浏览

python - Python中的嵌套While循环

我是python编程的初学者。我编写了以下程序,但它没有按我的意愿执行。这是代码:

有人可以帮助我吗?我真的会感激不尽!问候,吉拉尼