SoFunction
Updated on 2025-04-14

WMLScript Script Programming Page 3/9


Comment statements
Strictly speaking, comment statements are not real statements in WML Script, they are just a pre-pointing provision. However, it also has strict syntax and labeling methods, so we will introduce the WML Script annotation method in the form of a statement like other programming languages.
Comments have no effect when the program is executed, but can be used to interpret the program, thereby enhancing the readability of the program. In order to form a good programming style, we should develop good habits of writing comments. There are two ways to express comments:
(1) Comment one line with double slash lines, so that the characters in double slash sequence will become comments and will not be executed. This comment line can be written in a single line or placed after other statements.
For example, comments can be made as follows:
//Variable j is used for decimals of the number of days per month
j=0; //We assign j to 0 here
(2) The comment statement is specified through the symbols "/*" and "*/". This comment method can make multiple lines of comments, and the content between the symbols "/*" and "*/" is the comment statement. For example, you can make multiple lines of comments as shown below:
/*We define two variables: i and j. in:
i is used to describe the number of months in each year,
And j is used to describe the number of days per month*/
j=0; /*We assign j to 0*/
Return statement
The return statement is mainly used in the function body. Before the function ends, the result of the function processing can be returned to the statement calling the function through the return statement. Its syntax format is as follows:
return expression;
The following function gives an example of applying a return statement:
function square(x){
if(!((x)))return invalid;
return x*x
};
5.1.2 Conditional Statement
In a conditional statement, when a certain condition is met, some specified code will be executed, and when a certain condition is grouped, some other code will be executed. The conditional statement of WML Script is the if...else statement, and its general expression is as follows:
if(condition){
Code Block 1
}
else{
Code Block 2
}
In this way, when the condition is satisfied, code block 1 is executed; if the condition is not satisfied, code block 2 is executed. If there is only one statement in the code block and code block 2, then curly braces ({ }) can be omitted; and if there are multiple statements, curly braces must be included in it. In the if...else statement, the else part is optional, that is, we can use the following expression:
if(condition){
Code block
}
In this way, when the condition is satisfied, the code block is executed, and if the condition is not satisfied, nothing is done.
For example, if we need to judge a student's score, if it is greater than or equal to 60 points, then we think that the student's score is qualified. Otherwise, we think that the student's score is unqualified. At the same time, we record the status to the variable status type. The corresponding WMLScript statement is as follows:
if(score>=60) status="pass";
else status="fail";
For example, we can determine whether the weather is sunshines, assign a value to the variable myDay and accumulate the number of days of goodDays. The procedure is as follows:
if(sunShines) {
myDay="Good";
goodDays++;
}else
myDays="Oh well...";
Previous page123456789Next pageRead the full text