Changed "foreach" for "for" loops

Changed all the foreach loops to for loops in order to prevent garbage collector problems in iOS platform.