Real programs rarely keep arithmetic, comparison, and logical operators in separate boxes. Mixed expressions combine them: compute ten percent of gross and test whether it exceeds the limit in one IF line; subtract deductions from gross and branch when net is negative; connect a numeric validation with AND to a range test on a summed field. Mixed expressions are powerful and error-prone—operator precedence decides whether multiplication runs before greater-than, whether AND binds before OR, and whether your payroll exception fires on the wrong records. Beginners who write IF A + B GT C * D without parentheses rely on rules they have not memorized. This page teaches mixed forms in assignment and conditions, precedence interactions, parentheses as documentation, intermediate work fields as clarity tools, and production patterns that balance compact syntax with audit-friendly readability.
| Pattern | Example | Operator families |
|---|---|---|
| Arithmetic in IF | IF GROSS * 0.10 GT 500 | Arithmetic + comparison |
| Arithmetic both sides | IF A + B GT C + D | Arithmetic + comparison |
| Logical + arithmetic compare | IF A GT 0 AND B + C GT 10 | Logical + arithmetic + comparison |
| Assignment formula | NET = GROSS - TAX - FICA | Arithmetic in assignment |
| Grouped mixed IF | IF (A - B) GT 0 AND STATUS EQ A | All three with parentheses |
The most common mixed form puts arithmetic on one or both sides of a relational operator. IF GROSS * 0.10 GT LIMIT multiplies gross by literal percentage then compares product to limit field. Multiplication binds before GT—equivalent to computing tax amount mentally then asking if it exceeds limit. IF GROSS - DEDUCT LT 0 detects negative net without assigning NET first—useful for exception DISPLAY before correction logic runs.
1234567IF GROSS * 0.10 GT LIMIT PERFORM BONUS-TIER-2 END-IF IF GROSS - TOTAL-DEDUCT LT 0 DISPLAY 'NEGATIVE NET' EMPL-NUM END-IF
IF REG-HRS + OT-HRS GT STD-HRS + OT-CAP compares total hours worked against combined standard plus overtime ceiling. Each side evaluates independently before relational test. Field sizes must accommodate intermediate arithmetic on each side—overflow on left side may abend before compare executes. When formulas grow beyond two terms per side, use W hold fields: TOTAL-HRS = REG-HRS + OT-HRS; CAP = STD-HRS + OT-CAP; IF TOTAL-HRS GT CAP.
IF GROSS NUMERIC AND GROSS * 0.05 GT 100 combines class condition with arithmetic comparison—both must pass. IF DEPT EQ 10 OR GROSS + BONUS GT 5000 mixes OR with arithmetic on right alternative—precedence binds AND before OR when both appear; see order of evaluation. Parentheses clarify intent: IF (DEPT EQ 10 OR DEPT EQ 20) AND GROSS GT LIMIT requires department match and gross threshold.
1234567IF GROSS NUMERIC AND GROSS * TAX-RATE GT MIN-TAX PERFORM APPLY-TAX END-IF IF (STATUS EQ 'A' OR STATUS EQ 'P') AND GROSS GT 0 PERFORM PAY-CYCLE END-IF
Assignment is mixed when right side combines multiple arithmetic operators: NET = GROSS - FED - STATE - FICA. Subtraction associates left to right unless parentheses group terms. NET = (GROSS - FED) * ADJ-RATE mixes subtract and multiply—multiply binds tighter unless grouped. ROUNDED and TRUNCATED on assignment apply to final store into target, not to subexpressions individually—compute HOLD with explicit rounding if policy requires rounded intermediate tax before subtracting from gross.
12NET = GROSS - FED-TAX - STATE-TAX - FICA ADJ = (BASE + BONUS) * FACTOR ROUNDED
Typical precedence from highest to lowest: exponentiation, multiply and divide, add and subtract, relational comparisons, NOT, AND, OR. Expression IF A + B * C GT D multiplies B and C before adding A and before comparing to D. Expression IF A GT 0 AND B GT 0 OR C GT 0 groups AND before OR. When in doubt, parenthesize—auditors and your future self thank you. Full precedence tables live on order of evaluation and parentheses pages.
Parentheses override default precedence and document business grouping. IF (GROSS - DEDUCT) GT LIMIT compares net to limit, not gross to limit after unrelated subtract parsing. IF GROSS GT (LIMIT + ADJ) adds adjustment to limit before compare. Nested parentheses allowed within reason—IF ((A + B) * C) GT D. Excessive nesting signals refactor to PROC or hold variables.
Production maintainers often ban mixed IF lines beyond two operators. Pattern: compute in assignment, compare in simple IF. TAX-HOLD = GROSS * TAX-RATE ROUNDED. IF TAX-HOLD GT MAX-TAX. Benefits: DISPLAY TAX-HOLD in debug, reuse TAX-HOLD in PUT, single rounding point. Mixed expression still exists across two statements—clarity improves without changing business result when order matches.
12345TAX-HOLD = GROSS * TAX-RATE ROUNDED IF TAX-HOLD GT MAX-TAX TAX-HOLD = MAX-TAX END-IF NET = GROSS - TAX-HOLD
Mixing packed, zoned, and literals triggers conversion before arithmetic and comparison. IF N-FIELD + P-FIELD GT 1000 converts per product rules—usually succeeds when fields are valid numeric. Mixing alphabetic with numeric without conversion fails compile or produces nonsense—do not add NAME + 1. DATE fields compared after arithmetic require consistent representation—prefer validated internal dates for mixed date math.
DO WHILE WS-COUNT LT MAX AND GROSS GT 0 continues while both mixed conditions hold. Arithmetic in loop condition re-evaluates each iteration—changing GROSS inside loop affects next test. Avoid expensive mixed formulas in tight loops when simple counter LT suffices.
JOB assignment mixed expressions feed report fields before PRINT. Report LINE and SUM use field values after assignment—not inline IF arithmetic in LINE list beyond field names and literals per report grammar. Keep heavy mixed math in JOB; report displays results.
Mixed expressions do math and ask questions in the same sentence. If ten percent of your allowance is bigger than the piggy bank limit, you get a warning—that is multiply and greater-than together. If you are tall enough and your age plus bonus years is over ten, you ride—that is AND with plus and compare. Parentheses are like saying do this math part first in a quiet whisper before the loud question.
1. IF GROSS * 0.10 GT LIMIT contains:
2. In mixed expressions multiplication binds before GT meaning:
3. NET = GROSS - TAX - FICA is:
4. IF (GROSS - DEDUCT) LT 0 uses parentheses to:
5. IF A GT 0 AND B + C GT 10 mixes: