while
# Node.js
let i = 0;
while (i <= 5) {
console.log(i);
i++;
}
1
2
3
4
5
6
7
2
3
4
5
6
7
Output
0
1
2
3
4
5
1
2
3
4
5
6
2
3
4
5
6
# Go
(there's no while keyword in Go but the same functionality is achieved by using for)
package main
import "fmt"
func main() {
i := 0
for i <= 5 {
fmt.Println(i)
i++
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Output
0
1
2
3
4
5
1
2
3
4
5
6
2
3
4
5
6
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22