if statement
if(conditional expression) {
execute statement;
}
else{
execute statement;
}
If statement can also be multiple for example: if(){
}
else if(){}
if can also appear alone without else
E.g
The result is negative a is -1
switch statement
switch(expression)
{
case takes value 1:
execute statement;
break;
case takes value 2:
execute statement;
break;
····································
default:
execute statement;
break;
}
E.g
The result is Sprite
while statement
while(conditional expression) {
execute statement;
}
When the conditional expression is satisfied, it enters the while statement and executes consistently until the condition is not satisfied.
E.g:
The result is an even number between 0 and 100 (including 0)
do while statement
do{
execute statement;
}
while (conditional expression)
The do while statement is executed first and then judged
The while statement is judged first and then executed
for statement
for(assignment statement; conditional statement; change rule) {
execute statement;
}
E.g
The result is that the sum of 1 to 100 is: 5050
break statement
Scope of application: selection structures and loop structures
continue statement
Scope of application: applied to loop structures
That is, end this cycle and continue to the next cycle
For example, in the even-numbered example above, use continue as follows
The result is an even number between 0 and 100 (including 0)
-------------------------By chick