Potentially dangerous code below, line 2 Repeat: POTENTIALLY DANGEROUS CODE BELOW
var history = "";
for (start = 3; start = 1000; start += 1){
if(start % 5 == 0 || start % 3 == 0)
history += start + " "; }
Okay, this is the tenth time I’ve put JavaScript code in that’s frozen my browser. It’s putting my computer in shock. Are these panic attacks going to destroy her heart? Where can I learn about all the crap that might break my computer as I continue to learn and practice JavaScript? I’m looking for an exhaustive list, only.
Your loop:
for (start = 3; start = 1000; start += 1){The second part of a
for( ; ; )loop is the condition test. The loop will continue until the second part evaluates to false. To not create an infinite loop, change your code to:Note:
start+=1is equal tostart++. If you want a compact code, you can replace+=1by++.An overview of the three-part
for-loop,for(initialise; condition; increment):initialise– Create variables (allowed to be empty)condition– The loop will stop once this expression evaluates to falseincrement– This expression is executed at the end of the loopAlways check against infinite loops: Make sure that the condition is able to evaluate to
false.Commonly made mistakes:
i--decreases the counter, soi<100will always be true (unless the variableiis initialized at 100)for(var i=0,j=0; i<100; j++)(idoesn’t increase)