C++
C++でwhile文を使って繰り返し(ループ)処理を実行する
while文を使用して、繰り返し(ループ)処理を実行します。
while_loop.cpp
#include <iostream>
int main(void) {
int i = 0;
while(i < 5) {
std::cout << "loop count = " << i << std::endl;
++i;
}
return 0;
}
実行結果
$ g++ while_loop.cpp -o while_loop
$ ./while_loop
loop count = 0
loop count = 1
loop count = 2
loop count = 3
loop count = 4