21 while 循环

1,基本语法:

  ①循环变量初始化 ;

  while (②循环条件){

    ③循环体(多条语句);

    ④循环变量迭代

  }

2, ①循环条件是返回一个表示真假的表达式

  ② while 循环是先判断再执行语句

3,练习:

  不断输入姓名,直到输入 “ exit ” 为止

 1 #include<stdio.h>
 2 
 3 #include<string.h>
 4 void main() {
 5     //1,需要接收用户的输入,字符串,字符数组
 6     //2,<string.h>有一个strcmp函数,判断两个字符串是否相同
 7     //    int strcmp(str1,str2),返回0表示相等,非0表示不相等
 8     char name[10] = "";
 9     while (strcmp(name, "exit")!=0) {
10         printf("请输入姓名:");
11         scanf("%s", name);
12     }
13     printf("退出while");
14 }

原文地址:https://www.cnblogs.com/shanlu0000/p/12345653.html