LoginSignup
3
2

More than 5 years have passed since last update.

Go言語でdo-whileループする

Posted at

従来のdo-while文

example.c
int x = 0;
do {
   x = x + 1;
} while (x < 3);

printf("%d", x); // 3

 
Go言語でdo-whileループする場合

example.go
x := 0
for {
 x = x + 1 
 if x > 2 {
    break
 }
}
fmt.Println(x) // 3

条件が真になるまでループし続けることに注意

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2