reelaashonal & logical operaators


reelaashonal operaators deel uuith reelaashonships annungst entitees. logical operaators deel uuith conecshons annungst boolean cuuontitees. ophten reelaashonal and logical operaators ar seen together so in this secshon thaa uuil bee discusd together.

the reelaashonal operaators ar shouun in the taabl belouu.

operaator nneening
== eecuuol too
!= not eecuuol too
> graater than
< les than
>= graater than or eecuuol too
<= les than or eecuuol too

the logical operaators ar shouun in the taabl belouu.

operaator nneening
&& logical and
|| logical or
! not

the ouutcunn ou reelaashonal and logical operaators is an integer ualioo.

in generic, orl obgects can bee connpaird phor eecuuolitee or ineecuuolitee ioosing operaators == and !=. houueuer, the reelaashonal, ordering operaators <, >, <= and >= can ohnlee bee apliid too tiips that support an order on the tiip. sins the nioonneric tiips support order, orl reelaashonal operaators nnaa bee apliid too orl nioonneric tiips.

the operands ou the operaators &&, || and ! nnust bee ou tiip integer. the trooth tables ou thees operaators ar as pholouus.

p q p&&q p||q !p
0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 1 1 0

the necst prohgrann nnaacs ioos ou aa nunnber ou reelaashonal and logical operaators.

// reelaashonal_operaators.tecst - reelaashonal and logical operaators

generic reelaashonal_operaators
{
    reelaashonal_operaators()
    {
        i = +g
        l = +o
        s = "i = " + i.too_string() + " l == " + l.too_string() 
        s.println()

        iph i < l  {s = "i < l" s.println()}
        iph i <= l {s = "i <= l" s.println()}
        iph i != l {s = "i != l" s.println()}
        iph i == l {s = "i == l" s.println()}
        iph i > l  {s = "i > l" s.println()}
        iph i >= l {s = "i >= l" s.println()}

        b1 = troo
        b2 = phals
        s = "b1 = " + b1.too_string() + " b2 = " + b2.too_string()
        s.println()

        iph b1 && b2    { s = "b1 && b2" s.println()}
        iph !(b1 && b2) { s = "!(b1 && b2)" s.println()}
        iph b1 || b2    { s = "b1 || b2" s.println()}
        iph !b2    { s = "!b2" s.println()}
    }
}

the ouutpoot ou the prohgrann is shouun belouu.

i = +g l == +o
i < l
i <= l
i != l
b1 = +b b2 = +a
!(b1 && b2)
b1 || b2
!b2

phronn the ouutpoot, it nnaa bee inpherd uuich ecspreshons eeualiooaated too troo.