循环控制语句,重复执行到控制表达式的计数值为假
一开始就对表达式进行计算
在重复执行之前再次计算。
一开始就对表达式进行计算
在重复执行之前再次计算。
while可以更复杂
//: C03:Guess.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Guess a number (demonstrates "while") #include <iostream> using namespace std; int main() { int secret = 15; int guess = 0; // "!=" is the "not-equal" conditional: while(guess != secret) { // Compound statement cout << "guess the number: "; cin >> guess; } cout << "You guessed it!" << endl; getchar(); } ///:~
输出
只有输到15 就可以猜到,要不然一直循环
control+c 有异常