Control Statements FAQ's
  • = is used for assigning the value.
  • == is used for condition checking.
  • Logical Operators: && (logical AND), || (logical OR)
    • && → Checks first condition; if false, skips checking the second (short-circuit).
    • More efficient in conditional checks.
  • Bitwise Operators: & (bitwise AND), | (bitwise OR)
    • Always evaluates both conditions.
    • Works at the binary bit level.
  • break:
    • If the given condition is satisfied, break will terminate the loop or switch.
    • Control moves to the next statement after the loop/switch.
    • It works only inside loops or switch.
  • continue:
    • If the given condition is satisfied, continue will skip the particular iteration.
    • It does not terminate the loop, it just moves to the next iteration.
    • It works only inside loops.
  • exit(0):
    • Terminates the entire Java program immediately.
    • 0 means normal termination, while non-zero indicates abnormal termination.
  • return:
    • Exits from the current method and returns control to the calling method.
    • Can return a value (if method has a return type) or nothing (if void).
    • It works at method level.
  • while loop:
    • Checks the condition before executing the loop (entry-level condition checking).
    • If the condition is false initially, loop won’t run at all.
  • do-while loop:
    • Executes the loop body at least once, then checks the condition (exit-level condition checking).
    • Useful when you want the body to run at least one time.