Previous topic | Next topic | Ada Home Page | Index

Conditions

We have seen relational comparisons used for tests.
  • may want to combine several relational comparisons into a more complex test
  • use Boolean (logical) operators for this:

    There are several ways to write equivalent conditions, using and, or, xor, not, and the relational operators. Take care to write conditions as clearly as possible

    NOT

    NOT (TRUE)FALSE
    NOT (FALSE)TRUE

    Example:

    	not (age <= 21)
    

    AND

    FALSEandFALSE
    FALSE
    FALSEandTRUE
    FALSE
    TRUEandFALSE
    FALSE
    TRUEandTRUE
    TRUE

    Examples:

    	(age >= 21) and (age <= 65)
    	(age >  20) and (age <  66)
    	(sex = 'M') and (age >= 18)
    

    OR

    FALSEorFALSE
    FALSE
    FALSEorTRUE
    TRUE
    TRUEorFALSE
    TRUE
    TRUEorTRUE
    TRUE

    Examples:

    	(age < 18) or (sex = 'F')
    
    	not ( (age >= 18) and (sex = 'M') )
    
    	((age >= 60) and (sex = 'F')) or ((age >= 65) and (sex = 'M'))
    
    

    XOR (Exclusive OR)

    FALSExorFALSE
    FALSE
    FALSExorTRUE
    TRUE
    TRUExorFALSE
    TRUE
    TRUExorTRUE
    FALSE


    Previous topic | Next topic | Ada Home Page | Index
    c-lokan@adfa.oz.au / 13 Feb 96