DEV Community

Cover image for Difference Between conditions and loops?
Arul .A
Arul .A

Posted on

Difference Between conditions and loops?

Conditions:

  • Chooses which block of code runs depending on a boolean result.

  • Based on true/false decision.

  • Good for validation, branching, checks.

  • No automatic repetition.

  • Examples: if, else, switch.

let age = 17;

if (age >= 18) {
  console.log("Eligible");
} else {
  console.log("Not eligible");
}

Enter fullscreen mode Exit fullscreen mode

Loops :

  • Executes a block repeatedly until a condition fails.

  • Based on counter, condition, or data length.

  • Good for arrays, counting, tasks, automation.

  • Repeats until condition stops.

  • Examples: for, while, map, for...of

for (let i = 1; i <= 5; i++) {
  console.log("Count:", i);
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)