4-8.goto文と深層ループ
7573 ワード
#include
using namespace std;
int main(int argc, char* argv[])
{ // goto ,
/*
:
1 2 3 4
5 6 7 8
9 10 11 12
1,2,5,6,9,10,
*/
/************************* *************************/
int intArray[3][4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12} };
// 、
int colSize = sizeof(intArray[0]) / sizeof(int);
int rowSize = sizeof(intArray) / sizeof(int) / colSize;
cout << " :"<<colSize << endl;
cout << " :" << rowSize << endl;
//
for (int i = 0; i < rowSize; i++)
{
//
for (int j = 0; j < colSize; j++)
{
if (j == 2)
{
goto label;
// break , break ,goto
//label , ,
}
cout << intArray[i][j] <<" ";
}
label://label
cout << endl ;
}
return 0;
}
次にgoto文を用いてループを実現する
int i = 0;
loop:
cout << i << endl;
i++;
if (i < 10)
{
goto loop;
}
クリックしてください