// , using System;
class WhileDemo {
static void Main() { int num; int mag;
num = 435679; mag = 0;
Console.WriteLine(": " + num);
while(num > 0) {
mag++;
num = num / 10;
};
Console.WriteLine(" : " + mag);
}
}
.
: 435679 : 6
while . num. , mag, , , num 10. , num . , , mag .
for, while , . , , . while , 2 0 9.
// 2.
Using System;
class Power {
static void Main() { int e; int result;
for (int i=0; i < 10; i++) {
result = 1; e = i;
while (e > 0) {
result *= 2; e;
}
Console.WriteLine ("2 " + i + " " + result);
}
}
}
.
, while , . , for, while .
do-while
C# do-while. for while, , do-while . , do-while . do-while.
do {
;
} while ();
. , do-while while. do-while , .
do-while .
// .
Using System;
class DoWhileDemo { static void Main() { int num; int nextdigit;
num = 198;
Console.WriteLine(": " + num);
Console.Write(" : "); do {
|
|
nextdigit = num % 10;
Console.Write(nextdigit); num = num / 10;
} while(num > 0);
Console.WriteLine();
}
}
.
: 198
: 8 91
. ( num) 10. . num 10. , . , num .
foreach
f oreach , . C# , . f oreach 7, .
break
break , , . break, , , . .
// break .
Using System;
class BreakDemo {
static void Main() {
// break , for(int i=10; i <= 10; i++) {
if(i > 0) break; // , // i Console.Write (i + " ");.
}
Console.-WriteLine ("! ");
}
}