English
Basic Syntax
About 422 wordsAbout 1 min
2026-01-09
1. Custom Function Basic Syntax (Consistent with General Programming Language Syntax)
Example: <data_type> <variable> = <expression>
| Syntax Component | Description |
|---|---|
| Data Type | 12 major data types are provided in custom functions (case-sensitive). Refer to Data Types chapter for details |
| Variable | Name of the data for subsequent logic calls (cannot be the same as data type names) |
| Expression | The value assigned to the variable, which can be directly defined or an expression (ensure return type matches data type to avoid errors) |
Note: In custom functions, 'def' can be used to represent data type, which will be automatically recognized during compilation
Examples:
String str = "fxiaoke" //direct definition
Boolean boo = ["red", "blue", "green", "yellow"].isEmpty() //expression definition
def result = ["red", "blue", "green", "yellow"].isEmpty() //using def for data type2. switch
Used to evaluate given conditions and execute corresponding operations based on the evaluation result (true/false)
2.1 Definition
switch(<key>){
case <value-1>: statements-1; break;
case <value-2>: statements-2; break;
default: statements-3; break;
}
//Execution order: When key equals value-1, execute statements-1 and exit;
//if key doesn't equal value-1 but equals value-2, execute statements-2 and exit;
//...; if no matches found, execute statements-3 and exitNotes:
- Multiple case statements can exist
- default statement is optional but recommended (maximum one) to prevent errors from unmatched cases
- break statement can be omitted after each case/default, which means continuing execution (e.g. without break, when key equals value-2, it would execute both statements-2 and statements-3)
2.2 Example
Integer day = 3
switch (day) {
case 0: x="Today it's Sunday"; break;
case 1: x="Today it's Monday"; break;
case 2: x="Today it's Tuesday"; break;
case 3: x="Today it's Wednesday"; break;
case 4: x="Today it's Thursday"; break;
case 5: x="Today it's Friday"; break;
case 6: x="Today it's Saturday"; break;
}//Final result: Today it's Wednesday3. if-else
Used to evaluate given conditions and execute corresponding operations based on the evaluation result (true/false)
3.1 Definition
if(condition1) {
Execute this if condition1 is true
}else if(condition2){
Execute this if condition2 is true
}else {
Execute this if neither condition1 nor condition2 is true
}Note: if-else control statements must include both if and else, while else if can have zero or multiple instances depending on requirements
3.2 Example
String str = "fxiaoke"
if(str.contains("s")) {
str = "hello"
}else if(str.contains("f")){
str = "welcome"
}else {
str = "hi"
}//Final result: str=welcome