如何在间隔循环上添加30分钟 [英] How Do I Add 30 Minutes On An Interval Loop
问题描述
var StartTime = 8:00;
var EndTime = 17:00;
for ....
我想在每次循环运行任何建议时在这里添加循环30分钟?
的Javascript> ( var i = setHours( 8 ); i< toTime.count; i ++){
toTime.setMinutes(toTime.getMinutes()+ 30 );
}
更新
< pre lang =Javascript> while ( true ){
// ...
var toTime30 = new Date (toTime.getTime()+ toTime.getTimezoneOffset()* 30 * 1000 );
if ( true ){
< span class =code-comment> // 离开循环之前需要做的事情
破跨度>;
} 如果你想根据时间段在循环中添加更多时间,你可能最终会运行无限循环。
你可能真的需要改变循环内部的中断循环条件。在这种情况下,您使用了错误的循环。您需要在循环时使用。或者,在
下使用
下的True条件时使用无限时循环,在这种情况下,使用 break
在循环中的 if
语句中明确地从循环中断,例如:
while ( true ){
// < span class =code-comment> ...
breakCondition = // some布尔值基于条件
// 关于循环内执行的计算
if (breakCondition){
// 无论如何离开循环之前你需要做的事
break ;
}
}
请参阅,例如: http://www.echoecho.com/javascript9.htm [ ^ ]。
var StartTime= 8:00;
var EndTime= 17:00;
for ....
I want to add in a loop here 30 minutes every time the loop runs any suggestions?
for (var i = setHours(8); i < toTime.count; i++) {
toTime.setMinutes(toTime.getMinutes() + 30);
}
Update
while (true) {
// ...
var toTime30 = new Date(toTime.getTime() + toTime.getTimezoneOffset() * 30 * 1000);
if (true) {
// whatever you need to do before leaving the loop
break;
}
If you want to add more time in a loop based on time period, you may end up running infinite loop.
It's possible that you really need to change the break loop condition inside loop though. In this case, you are using a wrong kind of loop. You would need to use thewhile
loop. Alternatively, you use "infinite while" loop by using True condition underwhile
, and, in this case, usebreak
state in theif
statement inside loop to break from the loop explicitly, for example:
while (true) { // ... breakCondition = // some Boolean condition based // on the calculation performed inside loop if (breakCondition) { // whatever you need to do before leaving the loop break; } }
Please see, for example: http://www.echoecho.com/javascript9.htm[^].
—SA
这篇关于如何在间隔循环上添加30分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!