Last active
June 20, 2021 07:37
-
-
Save masaki-shimura/5e5843fdfe456593756eadce0a6ae9a4 to your computer and use it in GitHub Desktop.
【C++構文】whileループ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
void test_do_while() | |
{ | |
int loopCount = 0; | |
int MAX_LOOP_COUNT = 10; | |
bool isLoop = true; | |
do | |
{ | |
cout << "test_do_while loopCount : " + to_string(loopCount) + "\n"; | |
loopCount += 1; | |
// 終了条件の判定 | |
// 指定した回数に達していない時 ture を返す | |
isLoop = loopCount <= MAX_LOOP_COUNT ? true : false; | |
}while( isLoop ); | |
} | |
void test_endless_while() | |
{ | |
{ | |
int loopCount = 0; | |
int MAX_LOOP_COUNT = 10; | |
while(true) | |
{ | |
cout << "test_endless_while loopCount : " + to_string(loopCount) + "\n"; | |
loopCount += 1; | |
if(loopCount >= MAX_LOOP_COUNT) | |
{ | |
break; | |
} | |
} | |
} | |
{ | |
int loopCount = 0; | |
int MAX_LOOP_COUNT = 10; | |
do | |
{ | |
cout << "test_endless_do_while loopCount : " + to_string(loopCount) + "\n"; | |
loopCount += 1; | |
if(loopCount >= MAX_LOOP_COUNT) | |
{ | |
break; | |
} | |
}while(true); | |
} | |
} | |
void test_while() | |
{ | |
bool isLoop = true; | |
int loopCount = 0; | |
int MAX_LOOP_COUNT = 10; | |
while( isLoop ) | |
{ | |
cout << "test_while loopCount : " + to_string(loopCount) + "\n"; | |
loopCount++; | |
isLoop = loopCount <= MAX_LOOP_COUNT ? true : false; | |
} | |
} | |
int main(void){ | |
cout << "ループ処理関連の書き方振り返り\n"; | |
test_do_while(); | |
test_while(); | |
test_endless_while(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment