When to 'While' and when to 'For'



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++) {


A more complete error message:

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

Also keep in mind that not all statements end in semicolon


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!


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