开关&& for循环 [英] Switch && for loops
问题描述
我有'for'循环
并且在他里面有一个'switch'循环。
但是开关循环只执行ONCE。
为什么?我怎么能让它可以执行多次我想要的?
例如:
for (让我= 0;我< 5; i ++){
开关(某事[i]){
案例1:
alert(案例1已被激活!);
休息;
案例2:
alert( 案例2已被激活!);
休息;
}
我是什么尝试过:
寻找类似的文章问题。
i have a 'for' loop
and inside of him an 'switch' loop.
but the switch loop executes just ONCE.
why? and how can i make it executable as many time as i want to?
example:
for(let i = 0; i < 5; i++){
switch(something[i]){
case 1:
alert("case 1 has been activated!");
break;
case 2:
alert("case 2 has been activated!");
break;
}
What I have tried:
look for similar articles problems.
推荐答案
Aswitch
语句不是循环。此外,如果的东西[i]
不是1或2,那么什么都不会被拯救,并且会默默地通过。
你将不得不在上为
行设置断点并逐行调试以查看发生了什么。
您可能想要添加默认
案例来说明意料之外的值:
Aswitch
statement is not a loop. Moreover, if what is atsomething[i]
is not 1 or 2, nothing will be excuted and will silently pass.
You will have to put a breakpoint on thefor
line and debug line by line to see what is going on.
You may want to add adefault
case to account for unanticipated values:
switch (something[i]) {
// ...
default:
alert("unexpected value: " + something[i]);
break;
}
但是循环执行只是ONCE。
but the switch loop executes just ONCE.
可能是因为开关不是循环。你需要学习语言结构,我们不能为你服务。
JavaScript教程 [ ^ ]
这篇关于开关&& for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!