This shows you the differences between two versions of the page.
| — |
gnucap:manual:tech:rangeloop [2022/11/25 01:40] (current) felixs created |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | It could be good, or not. | ||
| + | One point about it is that this form does not explicitly specify the | ||
| + | order of the iteration. Therefore I would only use it in cases where | ||
| + | that is the intent, and even in that case, explicitly specify the type. | ||
| + | |||
| + | <code> | ||
| + | int main() { | ||
| + | int numberArray[] = { | ||
| + | 100, | ||
| + | 200, | ||
| + | 300, | ||
| + | 400, | ||
| + | 500 | ||
| + | }; | ||
| + | for (int number: numberArray) { | ||
| + | cout << number << " "; | ||
| + | } | ||
| + | return 0; | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | prints: 100 200 300 400 500 | ||
| + | .... or does it? | ||
| + | why not: 300 200 500 400 100 | ||
| + | .... ? | ||
| + | |||
| + | We really need a loop like this, or better yet .. one that supports | ||
| + | parallel operation. This would have been a good place to introduce it. | ||