If you want to execute one of several code blocks, you can use the switch statement:Syntax:Switch (n) { Case 1:Execution code block 1BreakCase 2:Execution code block 2BreakDefault:If n is neither 1 nor 2, execute this code } Working principle:
In Java, switch usage format:
switch (expression)
{case
constant expression 1: statement 1; break;
....
Case constant Expression 2: statement 2; break;
Default: statement;
after each case followed by a break, as long as the match to execute
The purpose of the machine: learn to use circular control statements to solve practical problems
On the machine content: Write a multi-branch selection structure program, according to individual monthly income, calculate the tax payable and
Part of the code in the just-created project includes the generation of random numbers in php, page jump, read/write, file rename, and switch statements.
The code is as follows:
Num = rand (1, 5 );Witch ($ num ){Case 1:$ Fp1 = fopen ("f1.dat",
{Code...} returns an error when running & amp; gt; the symbol is incorrect. what is the situation?
switch($rank) { case 1: $speed = 50; break; case 2: $speed = 48;
In my template, there is a volist loop. in the loop, switch is used to determine which file is contained. Similar to the following: {code...} There is a problem like this. When there are too many files, the template cannot be parsed and an empty
The switch declaration allows you to select an option for running a set of statements, based on a code return value expression.Switch (expression ){Case value_1:Statement (s );Break;Case value_2:Statement (s );Break; . . .Case value_n:Statement
This article describes the use of switch statements in PHP, which is similar to the switch usage in other statements, but note that there is a break statement.
Standard syntax for switch statements in PHP:
switch (expression)
{case
Label1:
1. General:
#include int main(void) { int i; for (i = 0; i switch (i) { case 1: printf("%d\n", i); break; case 3: printf("%d\n", i); break; case 5: printf("%d\n", i);
This section describes how to use C # To select control statements. The third lesson will achieve the following purposes:1. Learn how to use the "if" statement.
2. Learn how to use the "switch" statement.
3. Learn how to use the "break" statement in
HTML>
lang="en">
head >
charset= "UTF-8">
title>title>
type= "Text/javascript">
a=parseint (prompt (' first integer '));
b =prompt (' Operations to be performed ');
C =parseint (Prompt (' second integer '));
Switch(
Copypublic Function Switch (_ByVal ParamArray varexpr () as Object _) as Object
Instance
Function Matchlanguage (ByVal CityName As String) as StringReturn CStr (Microsoft.VisualBasic.Switch (_CityName = "London", "中文版", _CityName = "Rome",
It has been said that a really good program is no if. Else, of course, switch is not as good as if. Else JS specification inside is prohibit to use switch.
The Command object is the perfect solution to the problem.
Referring to a foreign blog:
Java provides two common branch control structures, the IF statement and the switch statement.Where The IF statement uses a Boolean expression or a Boolean value as a branching condition for branch control ,The switch statement is used to match
Switch-case retrun break, switch-caseretrun
{
If statements process two branches, the if-else-if structure must be used when processing multiple branches. However, if there are many branches, the more nested if statement layers, the program is not
Tutorials | control | Statements This section describes how to use C # to select a control statement, and the third lesson will achieve the following objectives:
1. Learn the use of "if" statements.
2. Learn the use of the "switch" statement.
3.
Learning notes for PHPSwitch statements. The Switch statement in PHP is used to execute different actions based on multiple different conditions. Switch statement if you want to selectively execute one of several code blocks, use the Switch
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.