[MonkeyScript] [TitleIndex] [WordIndex

   1 /** Iteration **/
   2 
   3 /* Objects */
   4 
   5 for ( let key in obj ) {
   6   // obj[key] contains the value
   7 }
   8 
   9 // If you don't care about the keys just use
  10 for each ( let value in obj ) {
  11   ...
  12 }
  13 
  14 /* Arrays */
  15 
  16 // Normal iteration
  17 for each( let item in array ) {
  18   // This will be the most useful most of the time
  19   // While unsafe in the browser an iterator makes this the cleanest method
  20   // of array iteration in MonkeyScript.
  21   // Use a different method if you also need item numbers
  22 }
  23 
  24 // Iterate over indexes
  25 for ( let index in array ) {
  26   // array[index] contains the value
  27 }
  28 
  29 // Classic iteration; Use this if you need to do real low level things
  30 for ( let i = 0; i < array.length; i++ ) {
  31   // array[i] contains item
  32   // you can skip and reiterate over things by modifying i
  33 }
  34 
  35 
  36 /** Inheritance **/


2010-07-23 04:25