_____________________________________________
How to use loops statement in C# ?
_____________________________________________
Pre-test Loops:
// no "until" keyword
while (c < 10)
c++;
for (c = 2; c <= 10; c += 2)
Console.WriteLine(c);
Post-test
do
c++;
while (c < 10);
// Array or collection looping
string[] names = {"Fred", "Sue", "Barney"};
foreach (string s in names)
Console.WriteLine(s);
// Breaking out of loops
int i = 0;
while (true) {
if (i == 5)
break;
i++;
}
// Continue to next iteration
for (i = 0; i < 5; i++) {
if (i < 4)
continue;
Console.WriteLine(i); // Only prints 4
}
____________________________________________________________________
____________________________________________________________________
No comments:
Post a Comment