In this article
For loop
Example:
var i : int;
for(i=1; i<5; i++)
{
Console.WriteLine("The value of i is " + i);
}
start loop
set variable to 1
if less than 5
add 1 to variable
otherwise
stop looping
While loop
Example:
var i : int;
i=1;
while(i<5)
{
Console.WriteLine("The value of i is " + i);
i=i+1;
}
Do...while Loop
var i : int;
i=1;
do
{
Console.WriteLine("The value of i is " + i);
i=i+1;
} while(i<5);
The while statement performs the test for deciding when to stop the loop.
If statement
if(something)
{
do something
}
else
{
do something else
}
Case...Switch
var i : int = 4;
switch(i)
{
case 1:
Console.WriteLine("The value is 1");
break;
case 2:
Console.WriteLine("The value is 2");
break;
case 3:
Console.WriteLine("The value is 3");
break;
default:
Console.WriteLine("The value isn't 1, 2 or 3");
break;
}
When a match is found, the accompanying statements are executed until a break statement is encountered or the switch statement ends. If you omit the break statement before the next case, the following statements will also be executed until a break is reached or you get to the end of the switch statement. Use the default clause to provide a statement to be executed if none of the values matches the expression.
Enumeration
Enumeration of a set is an exact listing of all of its elements.
The enum statement declares the name of an enumerated data type and the names of the members of the enumeration.
Example:
enum CarType {
Honda, // Value of zero, since it is first.
Toyota, // Value of 1, the successor of zero.
Nissan // Value of 2.
}
CarType.Nissan;