For example, the while statement is used to judge a condition and perform the corresponding task when the condition is met. However, if you want to do nothing when the condition is met, then you can assign it an empty statement to make the condition meet the empty operation:
while(!poll(device));
These are actually two statements composed of a while statement and an empty statement. The semicolon (;) here represents an empty statement. The purpose of these two statements is to wait until the poll() function is true().
Expression statement
Expression statements are used to assign values to variables, perform mathematical calculations, or perform function calls. Expression statements are also the most commonly used statements, and the syntax format is:
expression;
The following lines of the program are legal expression statements:
str="Hey"+yourName;
val3=prevVal+4
counter++;
myValue1=counter,myValue2=val3
alert("Watch out!");
retVal=16*(val3,counter);
Block statement
A block statement uses two curly braces ({ }) to contain a statement set to form a statement body. Many statements in WML Script require block statements to implement the statement body, and the syntax format of fast statements is:
{
statement list;
}
The following simple program is an example of using block statements:
}
vari=0;
var x=(b);
popUp("Remember!");
}
Variable statements
Variable statements are used for life variables and can be initialized and assigned to variables. If the user does not assign values, WML Script will automatically assign the variable of the variable statement life to an empty string (""). The basic syntax format is:
var variable name;
If multiple variables are lived at once, the neighboring variable names are separated by comma (,) and their syntax format is:
VAR variable name 1, variable name 2..., variable name n;
If you want to initialize the variable at the same time as the life variable, you can write it in the following syntax format:
var variable name = initialization
To facilitate everyone to better master variable statements, we give an extra program to use this statement:
function count(stu){
var result=0; //Initialize the variable while declaring the variable
while(str!=""){
var ind=0; //Every loop is initialized once
// In order to exit the loop, a statement that modifies and changes the value of the variable str should be provided in this block statement.
};
return result
};
function example(param){
var a=0;
if(param>a){
var b=a+1; //Declare the b variable and use the a variable to initialize the b variable.
}else{
var b=a+2; //Declare the c variable while using the a variable to initialize the c variable
};
return a; //Return the value of the variable a
};
Previous page123456789Next pageRead the full text