C
The operator used is wrong, needs to be a <(lower than). If you start from 0 and go to 10, and will increment you cannot verify if the number is greater than a certain value to determine if it will continue. Maybe the confusion is because it didn't quite understand how the condition works for, there has to be true to continue performing, so when it is false it closes the loop of repetition. The correct thing is to check if the number is still smaller than the desired target value that is 10.Then you may wonder why it should be just "less than" and not "less or equal to". Because you started from 0, and it's right to start from this number, not that it makes so much difference, the important thing is that it performs 10 times, because that is the statement of the problem, then it can start from the number you want and go to the number when to this, but it was convinced to start from 0, then the condition is true until the number 9, since the 0 count too. Therefore the signal should be only smaller, when it is equal, or it is reached in 10, it must be false, because starting from 0 the number 10 is the eleventh, one more than you want. So use it <= is wrong and the answer accepted and voted is wrong.#include <iostream>
#include <string>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
string nome;
cin >> nome;
cout << nome << endl;
}
}
See https://ideone.com/mJVGuQ . And https://repl.it/join/pjgvppno-maniero . Also https://github.com/maniero/SOpt/blob/master/CPP/Algorithm/Loop.cpp .How curious I could do this:for (int i = 1; i <= 10; i++)
There <= would be correct because it started from 1, but this is not how programmers make, leaving the pattern creates difficulties of understanding. We write codes for everyone to understand and so it is better to follow the standards already adopted.