can someone explain this code

what does this do exactly

1
2
  for (int i=0; i<5;i++)
      cout << shoes[i] << endl;
It prints elements from 0 to 4, all in a separate line, of shoes array.

for is the keyword for a range loop. The first argument before the ; is the initial index (an integer named i which starts at zero, the first index in every array in C and C++). The second argument is saying "loop until this is false", so it loops until i is less than 5 (0 to 4). The third one is how to increment the index. i++ is incrementing i by 1 in every iteration, but it could be i += 2, i += 3, and so on.

std::cout is the stream for the standard output device, that prints stuff. << is the operator for streams. shoes is (should be) an array that you can access specific elements using [x] syntax, where x is a positive number between 0 and (array length - 1). std::endl is "something" that prints a newline to the stdout and flushes it's buffer, so it gets printed, but is not required.

Hope it helps
thanks im new
Topic archived. No new replies allowed.