int i = 1 (runs once)i <= 10 (checked before each pass)i++ (runs after each pass)Best used for counter-controlled iteration — when you know how many times to loop.
The condition is tested after the body runs, so a do…while loop always executes at least once — useful for menus that must show before checking the exit condition.
case labelsbreak; or execution "falls through"->) doesn't fall throughdefault handles any unmatched valuebreakImmediately exits the loop (or switch) entirely.
continueSkips the rest of the current pass and moves to the next iteration.
| Operator | Meaning |
|---|---|
&& | AND — both must be true |
|| | OR — at least one true |
! | NOT — reverses a boolean |
^ | XOR — true only if exactly one is true |
&& and || stop evaluating as soon as the result is known — e.g. in a != 0 && b/a > 1, if a==0 the division never runs.
double uses binary floating point, which can't represent many decimal fractions exactly — this causes tiny rounding errors that add up in financial calculations.
| Method | Purpose |
|---|---|
add(other) | exact sum as a new BigDecimal |
subtract(other) | exact difference |
multiply(other) | exact product |
divide(other, scale, mode) | quotient with chosen decimal places & rounding mode |
setScale(n, mode) | rounds to n decimal places |
compareTo(other) | numeric comparison (ignores trailing zeros, unlike equals) |