I remember the first time I learned programming, I heard a sentence:"It is easy for beginners to learn and master a programming language, but if you learn a programming language and then learn a new language, it is difficult to master it.", Now I deeply feel the resistance in this regard.
In fact, process control and loop, including object-oriented knowledge, are basically the same in all languages. The only difference is that the format and norms at the time of writing are inconsistent. However, the differences in these aspects are quite subtle. Therefore, we often can quickly understand these differences by learning experience, but later we found that they did not make (PALM) Use (GRIP ).
The meaning of loop is actually repeated statement execution. Of course, there will also be corresponding conditional judgment, otherwise it will become an endless loop.What is the difference between a do loop and a while loop?: The do loop will execute a loop body before continuing to judge; while the while loop will first judge, and then decide whether to execute the loop body:
Double benJ, liV, muB, liX; int needY = 0; Console. writeLine ("Enter your deposit amount:"); benJ = Convert. toDouble (Console. readLine (); Console. writeLine ("Enter deposit interest rate:"); // + 1. The calculated result is Gold + interest. If only interest is required, + 1 is removed. It is very important to learn mathematics well. liX = Convert. toDouble (Console. readLine ()/100.0; liV = 1 + liX; liX = benJ * liX; Console. writeLine ("Enter expected earnings:"); do {muB = Convert. toDouble (Console. readLine (); if (muB <= benJ) {Console. writeLine ("the expected amount of earnings is lower than the principal; enter the amount of earnings higher than the principal:") ;}}while (muB <= benJ); while (benJ <muB) {benJ * = liV; ++ needY;} Console. writeLine ("annual interest {3}, saved to {0} year {4}, the sum of your principal and interest {1} can reach the expected goal {2 }. ", NeedY, benJ, muB, liX, needY> 1? "S": ""); if (needY = 0) Console. WriteLine ("high starting point, low target, in fact, you do not have to deposit to the bank at all ~ "); Console. ReadKey ();
This is a good one.Application scenarios of do loop:Use the do loop to determine whether the content entered by the user meets the conditions. If not, repeat the execution and exit the loop until the conditions are met (the while end of the do loop must be added ). The example also applies the previously learned ternary operator? , According to the condition judgment result, the string in front of the format.
A for Loop is suitable for applications with a specified number of times. during use, you must initialize a variable value as a counter (which can be declared in the for statement, however, the counter variable cannot be accessed in vitro ):
for (int i = 1; i <= 10; i++) { Console.WriteLine("{0}", i); }
After the for counter variable is declared, use the; sign to separate it, and then add the expression for condition judgment (which should involve the counter variable) I <= 10 to continue using the; sign to separate it, add operation I ++ for counter variables (no; end of number ). It is also feasible to try to remove I ++ and put it in a circular body.
The following is an example of how to use a for loop to print the mandelbrot set. Although you have understood the logic structure of the code, but the algorithm does not understand it, it is not pasted. However, I have extended my reading of the founder of the mandelbrot set:,And a mathematical structure :.It took me some time to read some documents. I would like to pay tribute to my predecessors.
Of course, the importance of the example is self-evident. I tried to think back to the "9-9 multiplication table" written in basic, and made a simple example in C. The principle is the same. Pay attention to the following details:
int i, k; for(i = 1; i < 10; i++) { Console.Write("{0}: ", i); for(k = 1;k <= i; k++) { Console.Write("{0}x{1}={2} " ,k, i, i * k); } Console.WriteLine("\n"); } Console.ReadKey();
This for loop nesting method is useful in implementing horizontal and vertical loops (output and Control). It is often used in excel VBA.
I have never remembered whether break or continue should be used at the bottom. However, the following example clearly describes it:
int i = 1; while (i <= 10) { if (i == 6) break; Console.WriteLine("{0}", i++); } for (i = 1; i <= 10; i++) { if ( i % 2 == 0) continue; Console.WriteLine("{0}",i); } Console.ReadKey();
In fact, both of them can be calledInterruptedHowever, the break is used to interrupt the current loop body (exit the loop body), while the continue is the current loop of the interrupted loop body (does not exit the loop body ).
As for goto, now let it go to hell. I have not encountered any applicable scenarios that can be properly used. I hope you can advise me.
It is very important to learn mathematics well. The programming language is only a tool for implementing the theory. The true principle still requires basic theoretical knowledge.
At this point, the learning in Chapter 1 is basically complete. At the end of each chapter of the book, there will be exercise questions and summary knowledge points. In the next note, we will first write the exercise questions and then write a program we want to implement. Objective: it is mainly used in combination with the knowledge points learned above to improve proficiency and deepen memory.
Little hope ~~~~