When to 'While' and when to 'For'


#1

https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/2/1?curriculum_id=506324b3a7dffd00020bf661#

Hello everyone, I can not seem to find out why I am getting and unexpected token on the following code:

var count = true;
var i;

while (count) {
    console.log("I am zero!");
    count = false;
};

for (i = 0, i < 7, i++) {
    console.log(i);
};

#2

A more complete error message:

$ xsel -b | node  # feed clipboard content (your code) into nodejs
[stdin]:9
for (i = 0, i < 7, i++) {
                      ^
SyntaxError: Unexpected token )

Also keep in mind that not all statements end in semicolon


#3

Oh thank you ionatan! it was my commas in the for parameters. They were supposed to be semicolons! :smiley: Whoops. Also, i removed the unnecessary semicolons. Thank you for mentioning that!


#4

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