Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?


for(let i = 0; i < 5; i++){

case 1:
alert("case 1 has been activated!");
case 2:
alert("case 2 has been activated!");

What I have tried:

look for similar articles problems.
Updated 23-Mar-19 8:28am

A switch statement is not a loop. Moreover, if what is at something[i] is not 1 or 2, nothing will be excuted and will silently pass.
You will have to put a breakpoint on the for line and debug line by line to see what is going on.
You may want to add a default case to account for unanticipated values:
switch (something[i]) {
   // ...
      alert("unexpected value: " + something[i]);
Share this answer
CPallini 23-Mar-19 11:57am    
phil.o 23-Mar-19 12:42pm    
Thank you, Carlo :)
but the switch loop executes just ONCE.

Probably because a switch is not a loop. You need to learn the language structures, we can't fo it for you.
JavaScript Tutorial[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900