8.When to 'while' and when to 'for'..please help me with the output!


hi all
This might be a silly question but please help me..
my code is
var count = 0;
var cities = ["ajmer","barmer","chandigarh","Delhi"]
for (var i = 0;i< cities.length;i++)
console.log("I have been to" + " " + cities[i]);
console.log("i am looping");
the output is
I have been to ajmer
I have been to barmer
I have been to chandigarh
I have been to Delhi
i am looping
i am looping
i am looping

Can someone please explain why 2 is printed at the end!!


Just ran the code, logs without the 2 coming up, I believe its something CA console related :slight_smile:

Are you still able to pass?


yes i am able to pass but the output 2 is still there!!


@benjnev thanks for precious time and support:slight_smile: