4.1 Java Basic syntax-three large flow control 4.1.1 Sequential control 4.1.2 Branch control
① Single Branch
IF (conditional expression)
{
Statement
}
② Dual Branch
IF (conditional expression)
{
Statement
}else
{
Statement
}
③ Multi-Branch
V method 1:
IF (conditional expression)
{
Statement
}else if (conditional expression)
{
Statement
}else
{
Statement
}
V method 2:
switch (conditional expression)
{
CASE constant 1:
Statement 1;
Break
Case constant 2:
Statement 2;
Break
...
CASE Constant N:
Statement N;
Break
Default
Statement
}
Note: The data type of the resulting result of the conditional expression should be the same as the type of the constant following the case.
The main data types available in switch are: Allow Byte,short,int,char,enum (enumeration), and so on.
4.1.3 Cycle Control
1. for Loops
2. while Loops
while (loop condition)
{
Statement Loop body
}
Description: The while loop is the first to judge the execution of the statement.
3. Do While Loops
Do
{
Statement Loop body
}while (cyclic conditions);
Description: The Do While loop is executed first and then judged.
Hanshunping Programming Tips :
- Take a complex problem and disassemble it into a simple question.
- How to die? Method: First fixed some values to implement the function, and then consider how to change the fixed value to a variable value.
- Cycle, pay attention to find the law.
Hanshunping the No. 04 step of the Java Process Control