# For .. in loop doesn't work properly

**URL:** <https://forum.kirupa.com/t/for-in-loop-doesnt-work-properly/316136>\
**Category:** flash\
**Created:** [November 13, 2010, 7:04pm UTC](https://forum.kirupa.com/t/for-in-loop-doesnt-work-properly/316136 "2010-11-13T19:04:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henky](https://avatars.discourse-cdn.com/v4/letter/h/e95f7d/32.png) [@Henky](https://forum.kirupa.com/u/Henky)\
**Post date:** [November 13, 2010, 7:04pm UTC](https://forum.kirupa.com/t/for-in-loop-doesnt-work-properly/316136/1 "2010-11-13T19:04:57Z")

</div>

In a small learning game, students must click on the proper button, representing a name of an element:  
[COLOR=magenta]on (release){[/COLOR]  
[COLOR=magenta]searchElement(“O”,no=11); [/COLOR][COLOR=dimgray]// searches for Oxigen[/COLOR]  
[COLOR=magenta]}[/COLOR]  
[COLOR=magenta]on (release){[/COLOR]  
[COLOR=magenta]searchElement(“H”,no=10); [/COLOR][COLOR=dimgray]// searches for Hydroxide[/COLOR]  
[COLOR=magenta]}[/COLOR]  
The names of the elements for that particular question, flash finds in an array:  
[COLOR=magenta]mcFormula.elementsArray = [“H”,“O”];[/COLOR]  
Things come together in this function:  
[COLOR=magenta]function searchElement(elementName,no){[/COLOR]  
[COLOR=magenta]for(var i:String in mcFormula.elementsArray){[/COLOR]  
[COLOR=magenta]if (mcFormula.elementsArray\* == elementName){[/COLOR]  
[COLOR=magenta]_root["mcCheck_"+ no].gotoAndStop(2);[/COLOR][COLOR=dimgray] // shows Ok. sign[/COLOR]  
[COLOR=magenta]}else{[/COLOR]  
[COLOR=magenta]_root["mcCheck_"+ no].gotoAndStop(3); [/COLOR][COLOR=dimgray]// shows Not Ok sign[/COLOR]  
[COLOR=magenta]} [/COLOR]  
[COLOR=magenta]trace(mcFormula.elementsArray\* + " = " + elementName); [/COLOR][COLOR=dimgray]//shows my good work…[/COLOR]  
[COLOR=magenta]}[/COLOR]  
[COLOR=magenta]}[/COLOR]  
It only works on the first item: “H”. The “O” will **not** be found, however trace shows me I’ve done things well.  
Can anyone tell me the reason for this?  
I’ve been looking the whole day at these few sentences, without result.
