MoonBit Language Tour MoonBit

Range

You can also use range in a for-in loop.

  • start..<end range is inclusive of the start value and exclusive of the end value.
  • start..=end range is inclusive of both the start and end values.
fn main {
  println("number 1 to 3:")
  for i in 1..<4 {
    println(i)
  }
  
  println("number 1 to 4:")
  for i in 1..=4 {
    println(i)
  }
}