Java Process Control Statement-(bottom)

Source: Internet
Author: User

Switch judgment statement:

Switch is to judge the value of the sentence, because the trouble is easy to write code, and there is a type limit, its function can also be completely replaced by the if else statement so now basically rarely use this statement, is the elimination of the wording. Notation

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/08/BB/wKiom1nmOgChamCUAA6uHR3L3CU889.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30145.png "alt=" Wkiom1nmogchamcuaa6uhr3l3cu889.png "/>

determine The value of I, match to the corresponding code and then execute, if there is no case to match, then execute default inside the expression. Every case should be followed by a break or it will be executed until the default,break is over and out of the meaning. The program executes the case match in order, and if the matching statement or default does not have a corresponding break to terminate, then the program continues to execute the match down, executing the matching expression until it encounters a BR e end of AK or switch statement .

While Loop statement :

The Loop statement is used to judge an expression after the loop executes the code in the block of statements, to determine whether the result of the expression is true, is to execute the code in the statement block, and always executes until the result of the expression is false. A loop is not executed if the result of the expression is judged to be false. While loop Flowchart:



650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/A7/6B/wKioL1nmN0yjlDULAAWuVd-6-ag177.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30475.png "alt=" Wkiol1nmn0yjldulaawuvd-6-ag177.png "/>

Write a loop to add a value can change the code,break can also be used for breaking the loop, if the value does not change will continue to execute into a dead loop. For example:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/A7/6B/wKioL1nmN02xvUIrAAT7iLyIWUE283.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30531.png "alt=" Wkiol1nmn02xvuiraat7ilyiwue283.png "/>


The value of I will never change, it will always be less than ten; The expression result is always true, so the code in the loop block is executed all the time and becomes a dead loop.

Therefore, it is common to add a code that can change the value to avoid a dead loop. For example:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/08/BB/wKiom1nmOgaAvGG6AAeAI3P5Gmw821.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30619.png "alt=" Wkiom1nmogaavgg6aaeai3p5gmw821.png "/>

the value of I will always increment until it is greater than ten, and the result is false, then jump out of the loop.

while loops are suitable for non-quantitative loops, such as not knowing how many times the code will be executed, and not knowing the exact number of cases that are appropriate for the while loop to complete.

the For loop is suitable for a quantitative cycle.

while loops can also be nested, and outer loops control the number of executions within the loop. For example:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/08/BB/wKiom1nmOgvD3_QeAAncGe-wTFo207.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30763.png "alt=" Wkiom1nmogvd3_qeaancge-wtfo207.png "/>



For Loop statement:

ForThe loop is kind of like putting whilethe loops are set up, forThere are many ways to use loops, which are commonly used:For (Data type Assignment;An expression;changing conditions){ }. The number of executions is different from a run point of view:For (data type execution once;each execution;each execution){ }. for Loops and whileThe loop process is almost the same as the result of the expressiontrueLoop executes the code in the statement block to the result of the expressionfalseSo far. The result of an expression isfalseThe loop is not executed. for Circular Flowchart:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/A7/6B/wKioL1nmN1mhwKdoAAr5M-DPDiI058.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.30990.png "alt=" Wkiol1nmn1mhwkdoaar5m-dpdii058.png "/>


for loops are suitable for writing quantitative loops that are relatively concise, for example:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/08/BB/wKiom1nmOhKBHK8QAAaFo24ss9o830.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.301023.png "alt=" Wkiom1nmohkbhk8qaaafo24ss9o830.png "/>

Because the code is concentrated in one parenthesis, it also reduces the occurrence of code leaks.



this notation of the For loop is the dead loop: for(;;) {}. There is also this:for(int i=1;i<=10;) {}. Because none of the statements that change the condition will naturally be looped and will not jump out.

The For loop can also be nested and more concise relative to the while loop. For example:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/A7/6B/wKioL1nmN2GBGilrAAozUIFCs_c053.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.301180.png "alt=" Wkiol1nmn2gbgilraaozuifcs_c053.png "/>


You can also print some patterns using nested loop output, such as triangles, diamonds, squares, and so on. For example:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/A7/6B/wKioL1nmN22CHmniABZGO_Hj75I563.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.301224.png "alt=" Wkiol1nmn22chmniabzgo_hj75i563.png "/>


Output Result:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/08/BB/wKiom1nmOiXzl1d3AAXZDCCUPQs187.png "style=" float : none; "title=" vip14-end bowl blowing book-10th and 11th section -12.301238.png "alt=" Wkiom1nmoixzl1d3aaxzdccupqs187.png "/>


This article is from the "12831981" blog, please be sure to keep this source http://12841981.blog.51cto.com/12831981/1973601

Java Process Control Statement-(bottom)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.