First, conditional statements
If statement
if (condition 1) {
Code 1
}
else if (condition 2) {
Code 2
}
......
else{
Code n
}
Switch statement
Not commonly used, only the following types of comparisons are supported: String, Char, Boolean, enum, integer
Second, the circular statement
While structure
while (loop condition) {
Loop body
}
Loop control statement:break: End the entire loop immediately
continue: Immediately ends the current number of loops and runs the next loop
Do.. While structure
do{Loop Body}
while (cyclic condition);
For structure
for (expression 1; loop condition; expression 2) {
Loop body
}
Three, array
Arrays: Used to hold multiple data of the same type
After an array is created, each entry must have a value, and if no assignment is made, the default value is used.
Number type: Default value is 0
String: Default value is null
Boolean type: Default value is False
Char type: The default value is
Array traversal: Gets the data for an item in the array, typically using a for loop, which overrides all subscripts of the array
foreach loop: can only be used to iterate over an array or collection, only in sequential traversal, with fast traversal speed
Iv. Functions (function)
Functions must be declared before they are used:
Modifier return type function name (formal parameter list) {function Body}
Formal parameter list: data type parameter name
Function call: Function name (argument list);
Parameters: Arguments used when declaring a function
Arguments: Parameters used when a function is called
When a function is called, the value of the argument is passed to the parameter.
Conditional statements, loops, arrays