The last time we talked about basic type conversions in Java and some common operators, today we talk about the underlying syntax in Java
Java Basic Syntax:
Conditional statements------Execute different statements according to different conditions;
If
If.. Else
If.. else if
If.. else if: else.. If.. Else
Switch
Loop statements-----repeat certain actions;
for (JDK1.5 syntax)
While
Do.. While
If statement:
If
If.. Else
If.. else if
If.. else if: else if;
If.. else if: else if: Else
Only one sentence that needs to be executed is to omit {} but not recommended;
Be careful not to add ";" After the IF ;
For Loop statement:
for (expression 1; expression 2; expression 3) {statement; ...;}
Example of a For loop statement:
Prime numbers in the output 101~200:
While & does while statement:
While statement:
while (logical expression) {statement; ...;}
Do While statement:
Do while{statement, ...;} while (logical expression);
Break & Continue
The break statement is used to terminate the execution of a block of statements in the body of a loop statement: for example:
Results:
The continue statement is used in the Loop statement body to terminate a cyclic process,
Skips a loop that is not executed under the Continue statement for example;
Results:
Switch statement (conditional statement supplement):
Switch () {
Case XX:
......
Case XX:
......
Case XX:
.....
}
Note: It is recommended to use the break statement for case penetration;
Default can be omitted, but omitted is not recommended;
The value inside the Switch "()" must be of type int, but Byte, Short,char is OK, because they are automatically converted to int.
Java Basic syntax