while


Node.js

  1. let i = 0
  2. while (i <= 5) {
  3. console.log(i)
  4. i++
  5. }

Output

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5

Go

(there’s no while keyword in Go but the same functionality is achieved by using for)

  1. package main
  2. import "fmt"
  3. func main() {
  4. i := 0
  5. for i <= 5 {
  6. fmt.Println(i)
  7. i++
  8. }
  9. }

Output

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5