iOS-C 第四天(上),ios-c第四天

來源:互聯網
上載者:User

iOS-C 第四天(上),ios-c第四天

1.while迴圈結構的使用;

2.隨機數的擷取;

3.do... while 迴圈體的使用;

4.for迴圈結構的使用;

5.break 與 continue 的區別;

 

1.while迴圈結構的使用

// while 結構   
// while (條件運算式) {   
//    迴圈體;   
// }  
//執行順序:判斷條件運算式是否成立,如果成立,執行迴圈體,執行完迴圈體後,再判斷條件運算式是否成立,如此往複,直到條件運算式不成立,跳出while迴圈;       
//死迴圈:
//    int a = 5;
//    while (a > 0) {
//        printf("Hello World!\n");
//    }   
//列印5次 hello world:
//    int a = 5;
//    while (a > 0) {
//        printf("Hello World!\n");
//        a--;
//    }
//    printf("END\n");   
//    int a =0;
//    while (a < 5) {
//        printf("%dHello World!\n", a);
//        a++;
//    }
//    int a = 0;
//    while (a <= 100) {
//        printf("%d ",a);
//        a++;
//    }
//    int a = 100;
//    while (a >= 0) {
//        printf("%d ", a);
//        a--;
//    }       
//計算1~100的和:
//    int i = 1, sum = 0;
//    while (i <= 100) {
////        sum += i;
////        i++;
//        sum += i++;
//    }
//    printf("sum = %d\n", sum);       
//輸出1~100的偶數:   
//方法一:
//    int i = 0;
//    while (i <= 100) {
//        if (i % 2) {
//            printf("%d ",i);
//        }
//        i++;
//    }       
//方法二:
//    int i = 0;
//    while (i <= 100) {
//        printf("%d ", i);
//        i += 2;''
//    }           
//列印1~100間7的倍數:
//    int i = 1;
//    while (i <= 100) {
//        if (i % 7 == 0) {
//            printf("%d ", i);
//        }
//        i++;
//    }       
//列印1~100間個位為7:
//    int i = 1;
//    while (i <= 100) {
//        if (i % 10 == 7) {
//            printf("%d ", i);
//        }
//        i++;
//    }       
//列印1~100間十位為7:
//    int i = 1;
//    while (i <= 100) {
//        if (i / 10 == 7) {
//            printf("%d ", i);
//        }
//        i++;
//    }       
//列印1~100間不是7的倍數且不包含7的數:
//    int i = 1;
//    while (1 <= 100) {
//        if (i % 7 != 0 && i % 10 != 7 && i /10 != 7) {
//            printf("%d ", i);
//        }
//        i++;
//       
//
//    }   
//    int a = 0,b = 0;
//    for (a = 1; a <= 100; a++) {
//        printf("%d ",a);
//        for (b = 1; b <= 10; b++) {
//            printf("\n");
//        }
//    }   
 

 

5.break 與 continue 的區別;    
//    for (int i = 1; i < 10;) {
//        if (i == 4) {
//            break;
//        }
//        printf("%d ", i);
//    }   
//break 跳出本層迴圈;可以把for 看做一層迴圈       
//    for (int i = 1; i < 10; i++) {
//        for (int j = 1; j < 10; j++) {
//            if (j == 4) {
//                break;
//            }printf("%d ", j);
//        }printf("\n");
//    }       
//continue:在迴圈中的使用   
//continue:結束本次迴圈   
//作用:加速迴圈的執行

5.break 與 continue 的區別;    
//    for (int i = 1; i < 10;) {
//        if (i == 4) {
//            break;
//        }
//        printf("%d ", i);
//    }   
//break 跳出本層迴圈;可以把for 看做一層迴圈       
//    for (int i = 1; i < 10; i++) {
//        for (int j = 1; j < 10; j++) {
//            if (j == 4) {
//                break;
//            }printf("%d ", j);
//        }printf("\n");
//    }       
//continue:在迴圈中的使用   
//continue:結束本次迴圈   
//作用:加速迴圈的執行   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.