Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Conditional statements allow programs to make decisions. They control which block of code runs based on whether conditions evaluate to true or false.
ifif (condition) { ... }Executes block only when condition is true
if-elseif (cond) { A } else { B }Chooses between two paths based on condition
else-ifif (c1) {} else if (c2) {} else {}Tests multiple conditions in sequence
switchswitch(val) { case 1: ... }Selects from multiple discrete values
ternarycond ? val1 : val2Inline conditional expression
Use if-else for boolean/range checks. Use switch for matching against specific discrete values (integers, chars, enums). Use ternary for simple inline assignments.