C continue

2018-05-19 19:25 更新

学习C - C continue

要跳过当前的迭代并继续下一个,请在循环体中使用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;
}

上面的代码生成以下结果。



以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号