Conditions in Pascal - Pascal programming

Selection and Repetition forms are controlled by a logical expression, or condition. For this reason, we will consider conditions first, before considering these two forms. Simple conditions, involving one relation, are shown in bold within the following (partial) forms:

Conditions may involve arithmetic expressions (variables, operations) as well as arithmetic relations ( <, =, etc.) The relations used for comparing two quantities are summarized below, in pairs which are opposites:

< less than> greater than = equal to>= greater than or equal to<= less than or equal to<> not equal to

Each of these simple relations can be used in a single logical expression (as X <= Y). If the variables in the logical expression have a value, then each of these relations evaluates to true or false. We can create compound conditions by joining simple conditions with one of the logical operations (AND, OR, and NOT). Here are a few examples of compound conditions:

Although the precedence of the three logical operations is defined with OR lowest, and NOT highest, we should use parentheses to avoid any possible confusion, either when first writing the program or later when reading it. It is often useful to negate compound conditions. To negate a logical expression consisting of two conditions joined by an AND we simply complement each of the conditions and change the AND to an OR. For example, consider the following expression:

We will consider such conditions in more detail when we discuss the Boolean type and Boolean expressions in Chapter 6. The informal presentation we have given here should suffice for most needs, provided that you use parentheses to avoid problems.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Pascal programming Topics