![]() All these comparison operators return Boolean values. The other comparison operators are: Less Than " =". If nSubTotal is greater than 100, the expression returns a value of True otherwise it returns a value of False. Where the operator is the Greater Than, " >", comparison operator. In our previous example, the condition is the expression: nSubTotal > 100 Boolean expressions are created using the comparison and Boolean operators. A Boolean expression is a piece of code that operates on, and/or results in, a Boolean value. As we will see, Boolean Logic is actually very simple and it is a key element of computer programming. Value comparisons and the Boolean expressionīoolean Logic is a system of mathematics that deals with true and false values, called Boolean values. ![]() The condition is a short piece of code that results in a true or false value, and it is called a Boolean Expression. This particular "if" block can be divided into two parts- the condition, and the code that is run when the condition is met. This pseudo code shows the simplest way to write a decision block. Now let’s rewrite the "if" block code (shown above) in pseudo code so we can better understand how it’s constructed. As we’ll see, this is especially important for complex conditions. It can’t be stated too often or too strongly that the first step of writing conditional code is to state the conditions clearly and make sure they do not conflict. All too often, the root problem is revealed as an unclear and/or conflicting statement of the necessary conditions. Problems with conditional execution are a very common issue posted to the forums. The conditions must make sense, not conflict with one another, and be testable from concrete values available to the code. The first rule of writing conditional statements is to clearly and simply express the complete set of conditions in English. If( nSubTotal > 100) event.value = nSubTotal * 0.10 The following code is placed in the calculation event for the discount field: var nSubTotal = this.getField("subtotal").value The Acrobat JavaScript code for performing this conditional calculation is exactly the same as our English statement, only it is expressed in JavaScript syntax. To express this idea in English, in the context of our form we might say " If the Subtotal is greater than 100, then set a 10% discount." In this case, we are comparing the value of the order’s subtotal to the constant value 100, then placing a percentage of the subtotal into the discount field if the result of the comparison is true. For example, on an order form we might want to give the customer a discount if they spend more than $100. In computer programming, all decisions are made by comparing values. While there are others, none is as generic and widely used as the "if" statement. In Acrobat JavaScript, the primary element of conditional execution is the "if" statement. It is the ability to execute a piece of code depending on some condition. One of the most important features of any programming language is the ability to make decisions, called Conditional Execution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |