--for Cycle
Grammar:
for (expression 1; expression 2; expression 3)
{
Circulation body;
}
Expression 1 is generally declared as a loop variable, the number of times the loop is recorded (int i=0;)
Expression 2 is generally a cyclic condition (i<10)
Expression 3 is usually the code that changes the loop condition so that the loop condition ceases to be true one day (i++).
Execution process:
The program first executes expression 1, declaring the number of times a loop variable is used to record a loop,
The expression 2 is then executed to determine if the loop condition is true, and if the expression 2 returns the result
The loop body is executed. After executing the loop body, execute expression 3, and then execute expression 2 to continue to determine whether the loop condition is true,
If it is set up, the loop body is resumed and if not, a for loop is popped out.
Find --999The number of daffodils between the two?//Narcissus number refers to this hundred number of//hundred cubic + 10 bit cubic + bits of cubic = = Current this hundred number//For example:153 theFetch the Hundred:153/ -Fetch to 10 bits:153%100/TenTake to Digit:153%10 for(intI= -; i<=999; i++) {intBai = i/ -;intShi = i%100/Ten;intGE = i%10;if(Bai*bai*bai+shi*shi*shi+ge*ge*ge==i) {Console.WriteLine (i)}}
The most classic case estimate for A for loop is the multiplication table.
for (int19; i++) { for (int1; j <= i; j++) { Console.Write(j+"*"+i+"="+i*j+"\t"); } Console.WriteLine(); }
continue--skip this cycle and perform the Next loop
break--end cycle, general mating conditions are only used
--Ternary expression
Grammar:
Expression 1-expression 2: expression 3;
Expression 1 is typically a relational expression.
If the value of expression 1 is true, then the value of expression 2 is the value of the entire ternary expression.
If the value of expression 1 is false, then the value of expression 3 is the value of the entire ternary expression.
Note: The result type of expression 2 must be the same as the result type of expression 3, and also consistent with the result type of the entire ternary expression.
//比如找出用户输入的两个数的较大值int n1 = Console.ReadLine();int n2 = Console.ReadLine();intmax = n1 > n2 ? n1 : n2;Console.WriteLine(max);
--a small thing that produces random numbers
//产生随机数//1、创建能够产生随机数的对象new Random();int num = r.Next(1,10)//产生1——9之间的随机整数double num1=r.NextDouble()//产生0——1之间的随机双精度浮点数
C # Process Control 2