### 非终止while循环

``````#include <iostream>
using namespace std;

int main()
{
int number, largest, counter = 1;
while (counter <= 10)
{
cout << "Enter a number: ";
cin >> number;
if (counter = 1)
{
largest = number;
}
else if (number > largest)
{
largest = number;
}
counter++;
}
cout << "\n\nThe largest number is: " << largest;
system("pause");
return 0;
}
``````

``````#include <iostream>
using namespace std;

int main()
{
int number, largest, counter = 1;
cout << "Enter a number: ";
cin >> number;
largest = number;
while (counter < 10)
{
cout << "Enter a number: ";
cin >> number;
if (number > largest)
{
largest = number;
}
counter++;
}
cout << "\n\nThe largest number is: " << largest << endl;
system("pause");
return 0;
}
``````

#### 10 个答案:

``````if (counter = 1)
``````

``````if (counter == 1)
``````

``````if( counter = 1) // assignment operator
``````

``````if( counter == 1) // equality operator
^^^^
``````

`if (counter = 1)`重新分配1来计算每个循环，这始终是`< 10`

``````  if (counter = 1)
``````

``````if (counter = 1)
``````

``````if (counter == 1)
``````

``````if (counter = 1)
``````

``````if (counter == 1)
``````

``````if( 1 == counter )
``````

``````if( counter == 1 )
``````

``````if( 1 = counter )
``````

``````if (counter = 1)
``````

``````if (counter = 1)
``````