For or while


#1

what's going wrong with my code?It showed my return statement is illegal...does someone have any idea:persevere:
// Write your loop below!
for(var i=0;i<=1000;i+=30){
return i;
while(i>998){
console.log("you almost do it!");
}
}


#2

That statement is an infinite loop. It enters the while loop, and never leaves because the while loop doesn't increment the variable " i " Just get rid of the while loop and you'll be good to go! :+1:


#3

it works fine when i change the 'return i ' to 'console.log(i)'


#4

Oop, look at that, I completely missed the "return i". I'd still suggest getting rid of the while loop that's in the for loop. You can replace that with an "if" statement without compromising the integrity of your for loop.

Yes, as soon as you hit a return statement, it stops the loop and returns the value to where it can then be used.

Is there anything specific you're trying to accomplish? Because at this point I'm not sure what it is that you're trying to do.

I can also explain the difference between "console.log" and "return" if you'd like.


#5

yes ,:blush:that would be very nice if you can tell me the difference between return &console.log()