How to do logical AND in conditionals?



  • If this AND that then jump

    ... how to do this in hyperPad?



  • @Deeeds Have an If stacked on top of another If. The more conditions you have, the longer your If chain is.



  • 0_1509858027335_C46BF54C-8EA6-41BB-97CB-00B8BE87BA9D.png



  • @Aidan-Oxley What about OR, XOR and NOT?



  • @Deeeds For Or, have the two Ifs next to each other underneath the event. I don’t know what XOR is. For not, press the “is equal to” when you tap the If behaviour, there will be a not equal to (≠).



  • 0_1509860759545_C98238C3-206F-41DF-980D-B976684252F0.png



  • @Deeeds

    (I'm going to use this to learn the code formatting on the forums)

    Like Aidan said, (P AND Q) can be represented by nesting ifs. It can be done as

    //# I'm not sure I fully get the syntax for comments
    output = 0 //# default to 0 if they aren't both true
    if P == 1:
        if Q == 1
            output = 1 //# set to 1 if they are both true
    return output
    

    P OR Q:

    output = 1 //# defaults to 1
    if P == 0
        if Q == 0
            output = 0 //# if NOT(P) AND NOT(Q) is true, return 0
    return output
    

    (P XOR Q) is the equivalent to ((P OR Q) AND NOT(P AND Q)), but there's an easy shortcut in that it's true when P ≠ Q:

    output = 0
    if P != Q:
        output = 1
    return output
    

    Edit: oh yeah, NOT P:

    output = 1
    if P = 1
        output = 0
    return output
    

    Edit 2: As hyperPad behaviours:
    0_1509869001029_IMG_0361.PNG



  • @Jack8680 INCREDIBLE!!!

    THANK YOU!!!!!!!


Log in to reply
 

Looks like your connection to hyperPad Forum was lost, please wait while we try to reconnect.