You are on page 1of 3
Selection Logic The IF Statement “if | did my homework, then I'd have better grades.” That statement would be conditional statement. This lesson is all about conditional statements. In a conditional statement we use, the "if statement. Here are the symbols used in a conditional statement: > Greater than < Less than >= Greater than or equal to Less than or equal to are equal Note: Notice the condition “are equal” are two equal sign. If you use only one equal sign, it assigns the value on the right to the variable on the left. For example x=1+2; the value of x will become 3; and x==1+2, if x=3 then the condition is true. Three Types Of Selection Logic And Syntax: 1. Single Alternative SYNTAX: if (condition) statement; 2. Double Alternative - if (condition is true) execute this; else execute this instead; ‘SYNTAX: If (condition) { statement; statement; } else statement; 3. Multiple Alternative SYNTAX: if (condition) statement; else if (condition) ‘statement; else if (condition) ‘statement; else statement; COMPOUND RELATIONALS (AND, NOT, OR, EOR) Combining more than one condition These allow the testing of more than one condition as part of selection statements. The symbols are: LOGICALAND && Logical and requires all conditions to evaluate as TRUE (non-zero). LOGICAL OR || Logical or will be executed if any ONE of the conditions is TRUE (non-zero). LOGICALNOT ! logical not negates (changes from TRUE to FALSE, vsvs) a condition. LOGICALEOR *% Logical eor will be excuted if either condition is TRUE, but NOT if they are all true.

You might also like