IOS getting started tutorial (2)-Control Flow
Int main () {// 2. control Flow // 2.1 if statement // 1. if (expression) {}// 2.if( expression) {} else {}// 3. there can be 0 or more else if, and the last else can also omit if (expression) {cx} else if (expression) {} else {} // 2.2 switch statement // 1. single-line code switch (n) {case 0: printf ("000000"); break; case 1: printf ("111111"); break; case 2: printf ("222222"); break; default: break;} // 2. multi-line code switch (n) {case 0: {printf ("000000"); printf ("000000"); break;} case 1: {printf ("111111 "); printf ("000000"); break;} case 2: {printf ("222222"); printf ("000000"); break;} default: break ;} // 2.3 Cycle Structure // 1. while loop while (expression) {// dosomething} // 2. for Loop for (int I = 0; I
2) {return 0 ;}// 2.4 goto statement, which is rarely used or not used. // It is usually used in a nested loop for (int I = 0; I
5) {goto outer ;}}outer: printf ("nested"); // 3. array // 3.1 defines the array tyoe arrayName [lenth]; // when the array is used to calculate the address, the element address = the first address + Memory occupied by the array variable * index // 3.2 array value assignment int arr [2] = {1, 2}; // 3.3 Use the array printf ("% d", arr [0]); // traverse the basic array element for (int I = 0, length = sizeof (arr) /sizeof (arr [0]); I
Append an example of two-digit array.
# Include
# Include
# Include
# Define NO_CHESS "success" # define BLACK_CHESS "●" # define WHITE_CHESS "○" # define BOARD_SIZE 15 // define the size of the chessboard static char * board [BOARD_SIZE] [BOARD_SIZE]; // define a two-dimensional array to act as the void initBoard () {int I, j; // assign each element to the Board Output for (I = 0; I