Sambar Server Documentation
|
CScript Flow Control |
and the for loop:while (expression) { ...block of statements to execute... }
The while loop continues to loop until the conditional expression becomes false. The condition is tested upon entering the loop. Any logical construction (see below) can be used in this context. The for loop is a special case, and is equivalent to the following while loop:for (expression_1; expression_2; expression_3) { ...block of statements to execute... }
expression_1; while (expression_2) { ...block of statements... expression_3; }
Conditionals are logical operations involving comparison of quantities (of the same type) using the following operators:if (conditional_1) { ...block of statements executed if conditional_1 is true... } else if (conditional_2) { ...block of statements executed if conditional_2 is true... } else { ...block of statements executed otherwise... }
Conditional operators are typically used to combine logical expressions, for example:
Conditional Operators Description < smaller than <= smaller than or equal to == equal to != not equal to >= greater than or equal to > greater than Boolean Operators Description && and || or ! not
These logical connectives employ a technique known as lazy evaluation. The left hand operand is evaluated first, and then the right hand is evaluated only one if it is required. Clearly false && anything is always false, true || anything is always true. In such cases the second test is not evaluated. The not operand reverses the state of a single logical value.x < 20 && x >= 10
Another conditional use is in the switch construct:if ( ! acceptable ) printf("Not Acceptable !!\n");
The appropriate block of statements is executed according to the value of the expression, compared with the constant expressions in the case statement. The break statements insure that the statements in the cases following the chosen one will not be executed.switch (expression) { case const_expression_1: { ...block of statements... } break; case const_expression_2: { ...block of statements... } break; default: { ...block of statements.. } }
© 2001 Sambar Technologies. All rights reserved. Terms of Use.