Syntax of the for without the counter

0

I'm a beginner in programming and I'm studying the C ++ language, so it's also my first time using this site. But finally after doing a basic course on the referred language, I downloaded a source code to understand a little of the practice.

Then reading a part of the code I came across this line of code:

for (Creature* spectator : list) { }

But when I was seeing this type of loop there were some arguments but it was defined as the following example > > For (int i = 0; i

asked by anonymous 26.12.2017 / 04:03

1 answer

0

% C ++ can be used in the traditional way with a counter, specifying the beginning of the count, the end, and the steps ( link ) or used as a more readable equivalent to a loop that operates on a variety of values, like all elements in a container, as in the case that you cite. In this case, it is counting all the elements of a list. You can see how to use this link at this link: link . In the latter way, it is used similar to for ( link ). Since you are learning, I suggest starting with simpler codes. I hope I have helped.

    
26.12.2017 / 04:29