Почему выражение обновления цикла for (i + 2) создает бесконечный цикл? [дубликат]C++

Программы на C++. Форум разработчиков
Anonymous
Почему выражение обновления цикла for (i + 2) создает бесконечный цикл? [дубликат]

Сообщение Anonymous »


I was doing an exercise in my textbook that asked us to output a vector's elements at even indices separated by asterisks. Then on a newline, do the same thing with the odd indices. So, if the vector contained 10 20 30 40 50 60, the output should be:

10*30*50* 20*40*60* The textbook gives us the starting code:

#include #include using namespace std; int main() { int numStudents; int i; cin >> numStudents; vector idNumbers(numStudents); for (i = 0; i < idNumbers.size(); ++i) { cin >> idNumbers.at(i); } And we need to finish the code. My initial solution was:

// Even indices for (i = 0; i < idNumbers.size(); (i + 2)) { cout

Источник: https://stackoverflow.com/questions/781 ... inite-loop

Вернуться в «C++»