This statement is often used in conjunction with switch statements; however, C# allows you to use it to break out of the current block of statements. The break statement is usually used to break out from an iteration statement block.
A labeled statement permits a statement to be prefixed by a label, and goto statements can be used to transfer control to a labeled statement.
This statement transfers control to a labeled statement unconditionally. In C#, any statement can be labeled. A colon follows a statement label, and a label identifier follows the goto keyword. The goto statement transfers control to the statement named by the label identifier.
If you overuse the goto statement, it can create code that is hard to read and follow. In general, it's a good practice to avoid using goto altogether by restructuring the code in a way that allows you to get around using the goto statements.
A 'do-while' loop is just like a 'while' loop except that the condition is evaluated after the block of code specified in the 'do' clause has been run. So even where the condition is initially false, the block runs once. For instance, the following code outputs '2':
syntax: foreach (variable1 in variable2) statement[s]
The 'foreach' loop is used to iterate through the values contained by any object which implements the IEnumerable interface. When a 'foreach' loop runs, the given variable1 is set in turn to each value exposed by the object named by variable2. As we have seen previously, such loops can be used to access array values. So, we could loop through the values of an array in the following way: