for loop Fun

Actionscript:
  1. var leng:int = 10;
  2. for (var i:int = 0, j:int = leng;  i <leng; i++, j = leng - i){
  3.     trace(i, j);
  4. }
  5.  
  6. /*outputs
  7. 0 10
  8. 1 9
  9. 2 8
  10. 3 7
  11. 4 6
  12. 5 5
  13. 6 4
  14. 7 3
  15. 8 2
  16. 9 1
  17. */

Looping backwards and forwards.

This entry was posted in Math, misc, one-liners and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*