I updated i = 12, but it s still freezing up like an infinity loop. more errors?


#1


for(i = 12 ; i > 0 ; i / 3){
    console.log(i);
}

var city = true

var loop = function(){
while(city){
    console.log("yes");
    city = false;
}
}
var sleep = false
do{
    console.log("no");
}
while(sleep);

loop();


#2

you don't get it, i thought you solved it, that is why i closed the topic. This:

i / 3

won't update i, as i showed you:

i = 10;
console.log(i/3); // will log 3.3333
console.log(i) // will log 10
i = i / 3
console.log(i) // will log 3.3333

lets look at the above code in more detail, after we temporary divided i by 3:

console.log(i/3); // will log 3.3333
console.log(i) // will log 10

i will still log 10 on the next line, since that was a temporary division (and didn't update i), we didn't update i, we did that here:

i = i / 3

this should help you to update i in your for loop


#3

after we divided i by 3:

console.log(i/3); // will log 3.3333
console.log(i) // will log 10

This is not correct

i is now 3.33333333333333
console.log(i/3); // will now log 1.111111111111
console.log(i) // will now log 3.33333333333


#4

it is correct. let me modified it to show you why it is correct.

i wanted to talk about the above code in more detail, it is in essence a flashback


#5

Ahh okay :slight_smile:

I only saw i = 10;


#6

no, you where right, it was a bit vague, it is better now :slight_smile: thank you :slight_smile:


#7

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