Loops
Written by: maffelu , 2009-04-16 17:58:51
for (int i = 0;i <= 5 ;i++ ) {
Console.WriteLine(i);
}
//Foreach with int
int[] numbers = new int[]{1, 2, 3, 4, 5};
Console.WriteLine("\nInt:");
foreach(int i in numbers)
{
Console.WriteLine(i);
}
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
int[] numbers = new int[]{1, 2, 3, 4, 5};
int count = 0;
//While with int
while (count < numbers.Length) {
Console.WriteLine(numbers[count]);
count++;
}
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
int[] numbers = new int[]{1, 2, 3, 4, 5};
int count = 0;
//Do...while with int
do
{
Console.WriteLine(numbers[count]);
count++;
} while (count < numbers.Length);
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
//A collection
int[] numbers = new int[]{1, 2, 3, 4, 5};
//An iterator
int count = 0;
//While with int
while (count < numbers.Length) {
Console.WriteLine(numbers[count]);
count++;
}
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
count = 0;
//Do...while with int
do
{
Console.WriteLine(numbers[count]);
count++;
} while (count < numbers.Length);
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
//For loop with int
for (int i = 0;i <= 5 ;i++ ) {
Console.WriteLine(i);
}
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
//Foreach with int
foreach(int i in numbers)
{
Console.WriteLine(i);
}
/*Outputs: * 1 * 2 * 3 * 4 * 5 */
Console.Read();
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.