Last active
June 20, 2021 07:58
-
-
Save masaki-shimura/31c32600b3b324621f88e31092d6e0b0 to your computer and use it in GitHub Desktop.
【C++構文】forループ
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_for_array() | |
{ | |
int numberTable[] = {0,1,2,3,4,5,6,7,8,9}; | |
for( int number : numberTable) | |
{ | |
cout << "ID:" << to_string(number) << "\n"; | |
} | |
} | |
void test_for() | |
{ | |
for( int i = 0 ; i < 10 ; i++) | |
{ | |
cout << "loop count :" << to_string(i) << "\n"; | |
} | |
} | |
void test_for_endless() | |
{ | |
int loopCount = 0; | |
int MAX_LOOP_COUNT = 10; | |
for(;;) | |
{ | |
cout << "loop endless count :" << to_string(loopCount) << "\n"; | |
loopCount++; | |
if(loopCount >= MAX_LOOP_COUNT) | |
{ | |
break; | |
} | |
} | |
} | |
int main(void){ | |
cout << "ループ処理関連の書き方振り返り\n"; | |
test_for(); | |
test_for_array(); | |
test_for_endless(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment