Do conditional expressions produce a Boolean result?

Fundamentals of IDL Syntax

LIAM E. GUMLEY, in Practical IDL Programming, 2002

Ternary Operator

In the following example, an if statement is used to find the minimum of two scalars:

An alternative to this statement uses the ternary operator ?: to form a conditional expression:

A conditional expression has the general form

where expr1 is an expression that yields a true or false result. If the result is true, the value of the conditional expression is set to expr2. If the result is false, the value of the conditional expression is set to expr3. The type of the conditional expression is determined by the type of expr2 or expr3. Since the precedence of the ternary operator is very low [see Table 2.6], parentheses around expr1 are not required. However, parentheses are recommended to visually distinguish expr1 from the possible result values [expr2 and expr3].

Read full chapter

URL: //www.sciencedirect.com/science/article/pii/B9781558607002500033

Discrete Time Process Algebra and the Semantics of SDL

J.A. Bergstra, ... Y.S. Usenko, in Handbook of Process Algebra, 2001

Syntax:

An operator application op [el,…,en] evaluates to the value yielded by applying the operation op to the current values of the expressions el,…, en.

A conditional expression if el then e2 else e3 fi evaluates to the current value of the expression e2 if the current [Boolean] value of the expression el is true, and the current value of the expression e3 otherwise.

A variable access v evaluates to the current value of the local variable v of the process evaluating the expression.

A view expression view [v, e] evaluates to the current value of the local variable v of the process with the current [pid] value of the expression e as its address.

An active expression active [s [el,…,en]] evaluates to the Boolean value true if the timer identified with the signal type s and the current values of the expressions el,…, en is currently active, and false otherwise.

The expression now evaluates to the current system time.

The expressions self, parent, offspring and sender evaluate to the pid values of the process evaluating the expression, the process by which it was created, the last process created by it, and the sender of the last signal consumed by it. Natural numbers are used as pid values. The pid value 0 is a special pid value that never refers to any existing process – in full SDL this pid value is denoted by null – and the pid value 1 is reserved for the environment. The expressions parent, offspring and sender evaluate to 0 in case there exists no parent, offspring and sender, respectively.

Read full chapter

URL: //www.sciencedirect.com/science/article/pii/B9780444828309500369

Embedded SQL, CLI Dynamic SQL, and SQL/PSM

Joe Celko, in Joe Celko's SQL for Smarties [Fifth Edition], 2015

38.4.5 Conditional Statements

There are two forms of conditional execution statements, the IF and the CASE. The syntax for the simple IF statement is the same as other languages.

IF

THEN

[ELSE ] END IF;

If the conditional expression yields TRUE, the statement in the THEN clause is executed. If the conditional expression tests to FALSE or UNKNOWN, then the ELSE clause is executed.

One or more IF statements can be nested, one within the other, by using an ELSEIF clause in place of the ELSE clause in the IF statement containing another.

IF

THEN

ELSEIF

THEN

ELSE

END IF;

Once the SQL statements to be executed have been selected, they execute in the same way as any ordinary list of SQL statements. This is important when creating handlers.

Examples:

IF a > 50 THEN

SET a = 50;

SET b = 1;

ELSE

SET b = 0;

END IF;

IF a > 50 THEN

SET a = 50;

SET b = 2;

ELSEIF a > 25

THEN SET b = 1;

ELSE SET b = 0;

END IF;

SQL/PSM has a CASE statement, which is not to be confused with the CASE expression in SQL. The simple CASE statement looks like the simple CASE expression with statement lists instead of scalar expressions in the THEN and ELSE clauses. Another difference is that it ends with END CASE, to keep the ADA-style statement terminators

A simple CASE works by evaluating equality between one value expression and one or more alternatives of a second value expression. For example:

BEGIN

DECLARE b INTEGER;

CASE b

WHEN 1 THEN UPDATE Foobar SET x = 1;

WHEN 2 THEN UPDATE Foobar SET x = 2;

WHEN 3 THEN UPDATE Foobar SET x = 3;

ELSE UPDATE Foobar SET x = 4;

END CASE;

END;

Like wise the searched CASE statement works the same way.

A searched CASE works by evaluating, for truth, a number of alternative search conditions. For example:

CASE

WHEN EXISTS [SELECT * FROM BILL]

THEN UPDATE Foobar SET x = 1;

WHEN a > 0 OR b = 1

THEN UPDATE Foobar SET x = a + b;

ELSE UPDATE Foobar SET x = -99;

END CASE;

A list of one or more SQL statements can follow the THEN clause for each of the conditional statements. Each alternative list of SQL statements in a CASE statement is treated in the same way, with respect to the behavior of exception handlers and so forth. They are not considered, in any sense, to be a single statement.

The conditional part of each WHEN clause is evaluated, working from the top of the CASE statement down. The SQL statements that are actually executed are those following the THEN clause of the first WHEN condition to evaluate to TRUE. If none of the WHEN conditions evaluate to TRUE, the SQL statements following the CASE statement ELSE clause are executed.

The presence of an ELSE clause in the CASE statement is optional and if it is not present [and none of the WHEN conditions evaluate to TRUE] an exception condition is raised to indicate that a WHEN or ELSE clause was not found for the CASE statement. If you do not want this exception, use an empty statement—ELSE BEGIN END.

Read full chapter

URL: //www.sciencedirect.com/science/article/pii/B9780128007617000383

Logic and Cognition, Psychology of

R. Revlin, in International Encyclopedia of the Social & Behavioral Sciences, 2001

1.3 Conditional Reasoning

Conditional syllogisms have as their central statement, a conditional expression of the form If P is true, then Q is true. Although conditional syllogisms are logically equivalent to categorical syllogisms, they have a communicative property that makes them especially interesting to psychologists in studying how people reason with them. The external marker If allows for an incredible range for conjecture: the reasoner can interpret it to mean let's suppose that …, or someone believes that … [e.g., Paul believes that if P, then Q, even though he may be wrong], or to perform some action, there is a set of conditions that must be followed [e.g., If you're drinking alcohol, you must be the right age], and so forth. That is, conditional syllogisms reveal the very property that makes human inference so dynamic: an ability to consider truth at many levels. When adults are presented with conditional syllogisms that have an unambiguous conclusion to be drawn, they are rapid and accurate:

If P then Q If P then Q.
P is true not Q is true.
Therefore: Q Therefore not P.

These problems are called modus ponens and modus tolens, respectively. The former tends to be more accurately solved than the latter, but people demonstrate real skill in solving these problems without any special training. In cases where the conclusion is ambiguous, students take longer to reach a decision and tend to equivocate and generally draw an incorrect conclusion:

If P then Q If P then Q.
Not P Q.
Therefore: ? Therefore: ?

Just as with other forms of inference, interpretation of the relational terms is critical to accurate judgment. A common error among adults is to assume that a kind of unique causal structure holds when they hear If P then Q. That P somehow causes Q and that it uniquely does this. This typically goes by the name biconditional interpretation: If P is true then Q is true and if Q is true, so must P [Taplin 1971]. You will notice that this is similar to the ‘converted interpretation’ on categorical syllogisms. It has been argued that there is a developmental sequence in the ability to solve conditional syllogisms which is linked to the child's interpretation of the conditionals. Very young children treat conditionals as conjunctions, slightly older children treat them as biconditionals, and adolescents and adults are able to treat them as one-way conditionals. Just as with categorical reasoning, conditional inference is sensitive to the content of the material reasoned about. This is particularly striking when people have to test conditional rules [Cox and Griggs 1983]. When the rules and situations match a type or schema [e.g., a permission rule: If you meet the requirements, you can perform an action], reasoning can be sharply more accurate than if the conditional rule is arbitrary [Cheng and Holyoak 1989, Cosmides and Tooby 1997]. The ease and ubiquity of this kind of reasoning suggests it may actually be a part of the human cognitive apparatus, part of our biological heritage that permits us to engage in effective social interactions.

Read full chapter

URL: //www.sciencedirect.com/science/article/pii/B0080430767014844

JavaScript

William J. Buchanan BSc, CEng, PhD, in Software Development for Engineers, 1997

26.7 Conditional statements

Conditional statements allow a program to make decisions on the route through a program.

26.7.1 if … else

A decision is made with the if statement. It logically determines whether a conditional expression is TRUE or FALSE. For a TRUE, the program executes one block of code; a FALSE causes the execution of another [if any]. The keyword else identifies the FALSE block. Braces are used to define the start and end of the block.

Relationship operators [>,=,

Chủ Đề