for loop problem in IE

I was coding some small javascript which should change the tab and modify some color and stuff and load some rss from somewhere its no big deal. somehow code worked in firefox but not in ie7. first I tought I manage to broke variables and naming. look at the code:

function ChangeTab(id,title){
for(k=1;k<4;k++){
if(k==id){
// section 1
}
else
{
// change like it did not choosed
}
}
}

its the simplest code ever. but somehow in ie it did not throw any debug dialog or any error at all. it was breaking the for loop “section 1” if it goes in there. here is the solution:
function ChangeTab(id,title){
for(var k=1;k<4;k++){
if(k==id){
// section 1
}
else
{
// change like it did not choosed
}
}
}

looks like no difference isnt it 🙂 look closer. ie’s javascript engine wants that k has to be declared there strange very strange. because normally ie can handle this small things. anyway what is the lesson from here. never trust ie 🙂

One thought on “for loop problem in IE”

Leave a Reply

Your email address will not be published. Required fields are marked *