Discover difference between switch case and if else, include the articles, news, trends, analysis and practical advice about difference between switch case and if else on alibabacloud.com
Java If...else if...else StatementsThe If statement can be followed by a elseif...else statement, which detects a variety of possible scenarios.When using the If,else if,else statement, the following points need to be noted:
The IF
First, Process Control OverviewProcess Control of the program-Program = data + algorithm-Any complex program algorithm can be implemented by "order", "branch", "Loop" three basic program logic combinations650) this.width=650; "src="
My answer is, more than two else if, or switch for more than two case. But is it normal to use a lot of if else and switch case in your code? Wrong! Most of the more than two of the if else and switch case should not appear as hard coded (hard-coded)
My answer is: If of more than two else, or switch of more than two cases. However
Code Is it normal to use if else and switch case in large quantities? Error! If else and switch case with more than two branches should not be hard-coded.
Where
- , StatementConcept: a semicolon (;) represents the end of a statementHabit: Write only one statement on a single line; write multiple statements on a line (poor code readability)Statement BLOCK: You can include multiple statements "{}" to wrap
What do you think is the most boring thing to see when you take over the legacy code? A complex UML? I don't think so. My answer is, more than two else if, or switch for more than two case. But is it normal to use a lot of if else and switch case in
[Switch] the difference between switch and if
If it is purely a number or character, we recommend that you use switch, because it will only retrieve the variable value once in the start switch brackets, and then compare this value with the case set
For else >>> to I in range (0,10): if i > 10:break; Else
print "Hello World"; Output: Hello World >>> to I in range (0,10): if i > 5:break; Else:print "Hello World"; No output
-------------------
That is, in a for loop, if you do not exit
1. Select Structure if statement format and its use
Format of the A:IF statement:
if (comparison expression 1) {Statement body 1;}else if (comparison expression 2) {Statement body 2;}else if (comparison expression 3) {Statement Body 3;}...else
-------Android Training, Java training, look forward to communicating with you! ----------1. Select the structure if statement format and its use Format of the A:IF statement:if (comparison expression 1) {statement body 1;}else if (comparison
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.