| Start |
|---|
| Foreach Loop foreach will iterate over any object of a class that implements syntax remarks
Consider this example: is equivalent to: |
| For Loop A For Loop is great for doing things a certain amount of time. It's like a While Loop but the increment is included with the condition. A For Loop is set up like this: Initialization - Makes a new local variable that can only be used in the loop. An example: Output: 0 You can also leave out spaces in the For Loop, but you have to have all semicolons for it to function. Output for 3: 3 |
| Do - While Loop It is similar to a |
| Looping styles While The most trivial loop type. Only drawback is there is no intrinsic clue to know where you are in the loop. Do Similar to For Another trivial loop style. While looping an index ( Foreach Modernized way of looping through Foreach Method While the other styles are used for selecting or updating the elements in collections, this style is usually used for calling a method straight away for all elements in a collection. It is important to note that this method in only available on Linq Parallel Foreach Just like Linq Foreach, except this one does the job in a parallel manner. Meaning that all the items in the collection will run the given action at the same time, simultaneously. |
Nested loops |
| break Sometimes loop condition should be checked in the middle of the loop. The former is arguably more elegant than the latter: Alternative: Note: In nested loops and/or |
| Do - While Loop It is similar to a |
| continue In addition to Here's a simple example: Will result in: Note: |
Read Article
https://develop.horje.com/learn/1434/reference