Posted By

tuffstudio on 10/07/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

letmein_xxi


Optimized Loops


 / Published in: ActionScript 3
 

  1. //Mostly when people are writing loops, it looks like this:
  2.  
  3. for(var i:int = 0; i < list.length; i++)
  4. {
  5. var item:MyItem = list[i];
  6. item.doSomething();
  7. item.doAnotherThing();
  8. }
  9.  
  10. //Take a look at the improved loop:
  11.  
  12. var item:MyItem;
  13. var total:uint = list.length;
  14. for(var i:uint; i < total; i++)
  15. {
  16. item = list[i] as MyItem;
  17. item.doSomething();
  18. item.doAnotherThing();
  19. }
  20.  
  21. //Want a more freaky way to define the same optimized loop?
  22.  
  23. for(var i:uint, item:MyItem, total:uint = list.length; i < total; i++)
  24. {
  25. item = list[i] as MyItem;
  26. item.doSomething();
  27. item.doAnotherThing();
  28. }

Report this snippet  

You need to login to post a comment.