C continue

2018-05-19 19:25 更新

學(xué)習(xí)C - C continue

要跳過當前的迭代并繼續(xù)下一個,請在循環(huán)體中使用continue語句。

continue;

例子


#include <stdio.h>
int main(void){
    int guess = 1;
    char response;

    printf("is your number %d?\n", guess);
    while ((response = getchar()) != "y")     /* get response */
    {
        if (response == "n")
            printf("Well, then, is it %d?\n", ++guess);
        else
            printf("Sorry, I understand only y or n.\n");
        while (getchar() != "\n")
            continue;                 /* skip rest of input line */
    }
   
    return 0;
}

上面的代碼生成以下結(jié)果。



以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號