Sometimes, when the IF statement is nested, all if statements look very similar because they are evaluated for an exact same expression, with the only difference being that each if statement compares the result of the expression with a different
This is a creation in
Article, where the information may have evolved or changed. This is the 10th article in the [Golang Series Tutorial] (/SUBJECT/2). Switch is a conditional statement that compares the value of an expression to a list of options
Today in the project encountered the use of switch statements to determine the condition, but the problem is more conditions, about dozens of conditions, full screen case judgment, whether there is a more elegant alternative to the switch statement?
123Switch statement, the switch statement is used to perform different actions based on several different conditions. 4 If you want to selectively execute one of several blocks of code, also use a switch statement. 56 The syntax structure is as
In the C language choice structure, the If--else statement generally refers to the choice structure which handles one or two branches, if the branch more also uses the If_else statement to be able to cause the program to run the efficiency to reduce,
The C language does not limit the number of branches that if else can handle, but when there are too many branches, it is not convenient to use if else, and it is easy to have an if else pairing error. For example, enter an integer that outputs the
------java training, Android training, iOS training,. NET training , look forward to communicating with you! -------1: operator (master)(1) Arithmetic operatorsa:+,-, *,/,%,++,--Note: Integers can only be divided into integers, and if you want
In one of the problems encountered in the switch, because of the switch execution sequence of the lack of understanding, here is a simple way to understand the byte code of the Switch execution order (the topic is as follows): Public classag{Static
Java selection structure (if statement switch statement)1.IF Selection Structure:①if (Boolean expression) {If the Boolean expression is true, the statement executed}* If there is only one statement after the IF statement, the curly brace of the IF
Explanation of switch statement usage in JavaScript
This article describes how to use the switch statement in JavaScript. It is the basic knowledge in JS learning. For more information, see
You can use multiple if... else if statements, such as the
Switch statement is a single conditional multi-branch switch statement, its general format is defined as follows ( where The break statement is optional):Switch ( expression ){Case constant Value :a number of statementsBreakCase constant Value :a
Switch is the most flexible type of control statement, which you need to be aware of when using switch:--The left curly brace "{" must be in the same row as switch--Conditional expressions are not limited to constants or integers--Multiple result
------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------"Easy error of variable"1. Why is the variable initialized to 0int sum,a=3;sum = Sum+aIf uninitialized, it becomes an indeterminate
When there are too many conditional judgment statements (if statements), you can use switch statements to write them. The basic structure of a switch statement is:switch (integer) {Case Integer value 1: statement; BreakCase Integer value 2:
1 /*Switch Statement2 format:3 switch (expression)4 {5 Case takes value 1:6 execute the statement;7 Break ;8 Case takes value 2:9 execute the statement;Ten Break ; One ..... A Default: - execute the statement; - Break ; the } - - */
casts of data types
public class example2{
int i=97;
Char c= (char) i; Cast of type
System.out.println ("c=" +c);
}
Hundred Record Entry dialog box
Import javax.swing.joptionpane;//dialog box to eject the method in the required package
public class
The following example converts IF-ELSEIF-ELSE into a switch statement
Copy Code code as follows:
# Use If-elseif-else
If ($value-eq 1)
{
"Beijing"
}
Elseif ($value-eq 2)
{
"Shanghai"
}
Elseif ($value-eq 3)
{
/*Switch statementswitch (expression) {Case value 1:Statement body 1;BreakCase Value 2:Statement body 2;Break....DefaultStatement body n+1;Break}Format interpretation of B:switch statements(1): switch indicates that this is a switch statementValue
Switch statements are also the most common logical control statements in object-oriented programming. The Switch statement is used to execute different actions based on multiple different conditions-that is, when the conditions are different,
Switch statement input level, output fractional segment#include using namespace Std;int main (){char grade;coutcin>>grade;Switch (grade){Case ' A ': coutCase ' B ': coutCase ' C ': coutCase ' D ': coutCase ' E ': coutdefault:cout}coutreturn
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.