Last practice 'for' loops - help


#1

for (var i = 100; i > 0; i -= 5); {
console.log(i);
}

I have no idea why this isn't working- says "your loop didnt log 100 to the console"


#2

You have a semicolon after your bracket

for (var i = 100; i > 0; i -= 5);


#3

The semicolon is BEFORE the bracket. Not after. Your incorrect wording aside, though... yeah. It shouldn't be there.


#4

After the parentheses and before the curly brace. Any way the problem with the semicolon here is that loops as well as conditions don't necessarily need the {} after them. If they are missing they just work on the very next statement. So the {} are more or less a workaround as they wrap all statements inside them into one single statement. But as this is not covered in the course and because they are also helpful to structure your code if you keep some formatting it's still recommend to always use {}.

Now as the semicolon ends a statement one could treat a solitary semicolon as a statement as well something like:

/*I have nothing to do ... and I'm done*/;

So as there are no {} but just a semicolon the loop now just counts up while doing nothing. So what you see is not the numbers counted down from 100 but just the number where it fails, because when the loop is ready it goes on with your code including your {} with the console.log.

Hope this helps a bit to understand what is happening and why semicolons in this situation can cause trouble.