Branching and Decisions

  1. Reading If and Else Branches

    A conditional runs work for the input cases described by its test and can supply a separate action for the other cases.

    Undergraduate
  2. Inclusive and Exclusive Comparison Boundaries

    Whether a comparison includes an endpoint can decide which quantities are admitted and whether two categories overlap.

    Undergraduate
  3. If Chains and Independent Conditions

    An if-elif chain chooses the first matching branch. Two independent checks can both run for one input.

    Undergraduate
  4. Guard Clauses and Early Returns

    A guard can handle inputs for which the remaining computation has no valid result or no work to perform.

    Undergraduate
  5. Short-Circuit Boolean Evaluation

    Some Boolean operations skip a later operand once the first result determines the answer.

    Undergraduate
  6. When And and Or Return Operands

    Python's Boolean operators and and or return a selected operand, so the result need not have Boolean type.

    Undergraduate
  7. De Morgan's Laws in Conditions

    Distributing a negation across a compound test exchanges conjunction and disjunction while negating each operand.

    Undergraduate
  8. Truth Tables for Program Decisions

    A truth table assigns an expected outcome to each combination of independent Boolean inputs.

    Undergraduate
  9. Conditional Expressions That Choose a Value

    A conditional expression chooses one value for use inside a larger expression or as the result of a function.

    Undergraduate
  10. Detecting Overlap in Condition Ranges

    A category rule should state whether its ranges overlap and which outcome to choose if several conditions apply.

    Undergraduate
  11. Covering Every Case in a Decision

    A decision is exhaustive when each allowed input reaches a defined outcome.

    Undergraduate
  12. Chained Comparisons in Python

    Python permits a sequence of comparisons that shares the middle operand and can stop at the first false comparison.

    Undergraduate
  13. Writing Predicates as Functions

    A predicate gives a name to a question that evaluates to true or false for a documented class of inputs.

    Undergraduate
  14. Decision Tables for Small Business Rules

    A decision table lists the relevant input cases and their expected outcomes before mapping them to implementation branches.

    Undergraduate
  15. Testing Membership in a Collection

    Membership asks whether an accepted value exists in a collection under that collection's comparison or lookup rule.

    Undergraduate
  16. Replacing Repeated Choices with a Lookup

    For a fixed key and one result per key, a data table can express a decision compactly.

    Undergraduate
  17. Branching on a Failed Conversion

    A failed conversion provides an observable result that can guide how a program reports invalid data.

    Undergraduate
  18. A State Transition Table for a Small Workflow

    Model a workflow by writing the next state for each allowed combination of current state and input event.

    Undergraduate
  19. Branching on an End Marker

    An end marker represents completion of an input sequence and needs a representation distinguishable from any valid record.

    Undergraduate
  20. Naming Boolean Flags

    A Boolean name should allow a reader to interpret the true case as a complete statement about the domain.

    Undergraduate
  21. Reading Nested Branches and Guards

    Nested conditions are useful when a later decision assumes that an earlier requirement was met.

    Undergraduate
  22. Classification with Ordered Thresholds

    An ordered series of thresholds can classify a numeric value into nonoverlapping bands when its endpoint rules are explicit.

    Undergraduate
  23. Writing Conditions on Dates and Times

    A condition about a calendar deadline depends on the date, time zone, and interpretation of the endpoint.

    Undergraduate
  24. Pattern Matching on Record Shapes

    Structural matching tests the shape of a value and can bind the fields of an accepted case where the language supports it.

    Undergraduate
  25. Designing a Default Branch

    A default branch can handle the remaining valid case or report a value outside a decision's supported domain.

    Undergraduate
  26. Case-Insensitive Decisions on Text

    A case-insensitive text comparison needs the same normalization on both operands and a rule suited to the kind of identifier.

    Undergraduate
  27. When a State Transition Can Be Repeated

    An idempotent transition reaches the same intended state when the same operation is applied again.

    Undergraduate
  28. Intentional Fall-Through in Switch Statements

    Some languages can continue from a matching case into following case bodies unless control leaves the switch.

    Undergraduate
  29. Recognizing Monotone Predicates

    On an ordered domain, a monotone Boolean predicate changes truth value at most once in the relevant direction.

    Undergraduate
  30. Keeping Conditions Free of Surprising Effects

    A condition is easier to move and combine when its evaluation reads stable input and has no surprising state changes.

    Undergraduate