Reputation: 120
I am looking for a simple way to iterate through a set of integers in C++. For example, if I had an integer variable 'x' and wanted to use the increment statement 'x++' continuously over 4 integer values, the desired output would be something like '0 1 2 3 0 1 2...'.
I know that a circularly linked list is a solution, but it just seems like overkill to me, I really need something short and sweet. I suspect that enumerated types may be able to do something like this, but my research has not turned up anything.
Upvotes: 1
Views: 2136
Reputation: 6557
Try this:
for (int i = 0; i < n; i = i+4) {
for (int j = 0; j < i; j++) {
// print here
}
}
Upvotes: 0