github.com/mattn/anko@v0.1.10/core/testdata/for.ank (about)

     1  
     2  x = 0
     3  for a in [1,2,3] {
     4    x += 1
     5  }
     6  is(3, x, "for a in range [1,2,3]")
     7  
     8  x = 0
     9  
    10  for {
    11    x += 1
    12    if (x > 3) {
    13      break
    14    }
    15  }
    16  is(4, x, "for loop")
    17  
    18  func loop_with_return_stmt() {
    19    y = 0
    20    for {
    21      if y == 5 {
    22        return y
    23      }
    24      y++
    25    }
    26    return 1
    27  }
    28  is(5, loop_with_return_stmt(), "loop with return stmt")
    29  
    30  func for_with_return_stmt() {
    31    y = 0
    32    for k in range(0, 10) {
    33      if k == 5 {
    34        return y
    35      }
    36      y++
    37    }
    38    return 1
    39  }
    40  is(5, for_with_return_stmt(), "for loop with return stmt")
    41  
    42  x = 0
    43  for a = 0; a < 10; a++ {
    44    x++
    45  }
    46  is(10, x, "C-style for loop")
    47  
    48  func cstylefor_with_return_stmt() {
    49    y = 0
    50    for i = 0; i < 10; i++ {
    51      if i == 5 {
    52        return y
    53      }
    54      y++
    55    }
    56  
    57    return 1
    58  }
    59  
    60  is(5, cstylefor_with_return_stmt(), "C-style for loop with return statement")
    61  
    62  resp = {
    63      "items": [{
    64          "someData": 2,
    65      }]
    66  }
    67  
    68  x = 0
    69  for item in resp.items {
    70      x += item.someData
    71  }
    72  
    73  is(2, x, "dereference slice element")
    74  
    75  nil