Skip to content

Instantly share code, notes, and snippets.

@masaki-shimura
Last active June 20, 2021 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masaki-shimura/31c32600b3b324621f88e31092d6e0b0 to your computer and use it in GitHub Desktop.
Save masaki-shimura/31c32600b3b324621f88e31092d6e0b0 to your computer and use it in GitHub Desktop.
【C++構文】forループ
#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