For Loop statement format:
for (int1; /* Initial conditions */ ; /* Cycle Conditions */i++/* status change */) { // loop body, execute code ; (break; jump out of the loop body) }
For the poor lifting method
Use the loop to go through all the possible situations, and then use the IF condition to filter out the results satisfying the requirements.
For iterative method
There is a certain regularity, from the initial situation according to the law constantly solve the intermediate situation, the final derivation of the results.
1 for several numbers and
Console.WriteLine (" Please enter a number:"); int a = Convert.ToInt32 (Console.ReadLine ()); int 0 ; for (int1; I <= A; i++) { = sum + i; } Console.WriteLine (" The sum of the numbers you enter is:" + sums);
2 finding factorial
Console.WriteLine ("Please enter a number:"); intA =Convert.ToInt32 (Console.ReadLine ()); intJC =1; for(inti =1; I <= A; i++) {JC= JC *i; } Console.WriteLine ("The factorial of the number you enter is:"+JC); intCJ =1; for(inti =1; I <=9; i++) { for(intj =1; J <=9; J + +) {CJ= i *J; Console.Write (i+"*"+ j +"="+ CJ +" "); } Console.WriteLine (); }
3. Ask for an even number within 100
// ask for all even numbers within 100 for (int0; i++) { if20)//% represents redundancy { Console.WriteLine (i); } }
4. Find the height of the N-Times basketball Ball
//the height of the blue ball bouncing upConsole.WriteLine ("Please enter the number of times:"); intA =Convert.ToInt32 (Console.ReadLine ()); DoubleGao =5; for(inti =1; I <= A; i++) { if(I >5) {Gao=0; } Else{Gao= GAO/2; }} Console.WriteLine ("Section"+ A +"the height of the second bounce is:"+ Gao. ToString ());
The sum of the FOR Loop statement, factorial, courtship, n times the height of the basketball jump