This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditional with AND and OR logic confusion

I'd like to branch to a certain Label if X=32 -- but only if (N=6 and O=6) or if (N=0 and O=0).

How must I construct that conditional?

Len

ps: Are there any limits to this? Actually, (N=6 and O=6) and (N=0 and O=0) are only two of some 173 conditions that I must state.

Parents
  • You can construct basically any level of complex conditional statement up to the limits of the memory in the board, the memory in the PC running the compiler or possibly any limitations claimed by the compiler (unless you use an assembler in which case only the memory in the ARM will limit your complexity).

    If using C - just make sure to use the required number of parentheses to inform in which order the subexpressions should be evaluated.

    Or if the expression gets too big - check if you can split it into multiple separate statements. Keeping it as a single expression has the advantage that the compiler can perform lazy evaluation.

    See your problem as a logic tree. You either have a sequence of multiple "or" statements where each term ored may be a new complex subexpression. Or you have a sequence of "and" statements where each term may possibly be a new complex subexpression.

Reply
  • You can construct basically any level of complex conditional statement up to the limits of the memory in the board, the memory in the PC running the compiler or possibly any limitations claimed by the compiler (unless you use an assembler in which case only the memory in the ARM will limit your complexity).

    If using C - just make sure to use the required number of parentheses to inform in which order the subexpressions should be evaluated.

    Or if the expression gets too big - check if you can split it into multiple separate statements. Keeping it as a single expression has the advantage that the compiler can perform lazy evaluation.

    See your problem as a logic tree. You either have a sequence of multiple "or" statements where each term ored may be a new complex subexpression. Or you have a sequence of "and" statements where each term may possibly be a new complex subexpression.

Children
  • If using C - just make sure to use the required number of parentheses to inform in which order the subexpressions should be evaluated.

    I think it's worth pointing out that parentheses don't necessarily affect the order of evaluation but do affect precedence. This is usually what is desired, but not always. To guarantee order of evaluation it is necessary to ensure that sequence points appear between expressions.