8. when to while and when to for


#1


Hello, my code is in shambles, im receiving an unexpected token alert "=="


var count == i
while (count) {
    console.log ("heaven yea")
}
for (i=2; i < 100; i=2); {
    document.write("Current Count : " + count );
}
count = false


#2

var count == i

what does it mean?if you want to assign a value to a variable then use assignment operator.suppose i want to assign 5 to a variable named x then i would do

x=5

for boolean vaule

x=true;

or

x=false;

we use == or === for checking whether two values are equal or not.
now your both loop is infinite.

count = false should be inside of while loop.

and

for (i=2; i < 100; i=2); //remove ;

first remove the ; at the end
syntax:

for ([initialization]; [condition]; [final-expression])
   statement

final-expression to be evaluated at the end of each loop iteration.if you want to increase the value by 2 then do

i+=2
or
i=i+2


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.