#include <iostream>
int main()
{
int myArray[5]; // array of 5 integers lol
int i;
for (i=0; i<5; i++ ) // 0 - 4
{
std::cout << "Value for myArray[" << i << " ]: ";
std::cin >> myArray[i];
}
for (i = 0; i<5; i++)
std::cout << i << ": " << myArray[i] << std::endl;
return 0;
}
Why is i++ required for this program to work?
Because if you don’t execute
i++(or any other statement which incrementsi),iwill remain0, the conditioni < 5will always remain true and the loop will never end.