Foreach Statement

The foreach statement repeats a group of embedded statements. for each element in an array or an object an collection. The foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the content of the collection to avoid unpredictable side effects.

Example:

class ForEachTest
{
static void main(String [] args)
{
int [] fibarray=new int[]{0,1,2,3,5,8,13);
foreach(int i in fibarray
{
System.console.WriteLine(i);
}
}
}

For Statement

The for loop executes a statement or a block of statements repeatedly until a specified expression evaluated to false. The for loop is handy for iterating over arrays and for sequential processing. In the following example, the value of int i is written to the console and i is incremented each time through the loop by 1.

Example:

using system;
class ForLoopTest
{
static void main(String []args)
{
for (int i=1;i<=5;i++)
{
Console.Writeline(i);
}
}
}

Looping Statement

You can create loops by using the iteration statement. Iteration statements cause embedded statement to be executed a number of times, subject to the loop-termination criteria. These statements are executed in order, except when a jump statement is encountered.

The following keywords are used in iteration statements:
  • do
  • for
  • foreach
  • while

Branching Statement

Changing the flow of control in a program in response to some kind of input or calculated value is an essential part of programming language. C# provide the ability to change the flow of control, either unconditionally, by jumping to a new location in the code, or conditionally, by performing a test.

What is Boolean Logic ?

The bool type represent Boolean logical quantities. The possible values of type bool are true or false.
No standard conversion exist between bool and other types. In particular, the bool type is distinct and separate from the integral types, and a bool value cannot be used in place of integral value, and vice versa.

The Goto Statement

The goto transfer the program controls directly to a labeled statement. A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement. The goto statement is also useful to get out of deeply nested loops.