🔀 Control Flow Statements

Last Updated: Jan 2026


Control Flow Statements decide which part of your program will run, when, and how many times. They give your program the ability to make decisions and repeat tasks.


Why Control Flow is Important?

Without control flow, JavaScript would just run your code line-by-line from top to bottom. Control flow lets you:

  • Run different code based on a condition.
  • Repeat code multiple times.
  • Skip or stop parts of a loop.

Real-life Analogy:

  • Conditional: If it's raining, take an umbrella.
  • Loop: Walk until you reach your destination.
  • Jump: If you see danger, stop immediately.

Main Categories

  1. Conditional Statements — Decision making.
  2. Looping Statements — Repeat a block of code.
  3. Jump/Transfer Statements — Change the normal sequence of execution.

CategoryKeywordsPurpose
Conditionalif, else if, else, switchRun different code based on a condition
Loopingfor, while, do...whileRepeat code multiple times
Jumpbreak, continueSkip or stop parts of a loop

Code Previews

Conditional Example:

int x = 10;

if (x > 0) {
  // Conditional
  printf("Positive number");
} else {
  printf("Non-positive number");
}

// switch example
char color[] = "red";
switch (color) {
  case "red":
    printf("Stop!");
    break;
  case "green":
    printf("Go!");
    break;
  default:
    printf("Caution!");
}

Loop Example:

for (int i = 0; i < 3; i++) {
  printf("Loop iteration:", i);
}

int j = 0;
while (j < 3) {
  printf("While loop:", j);
  j++;
}

Jump Example:

for (int i = 0; i < 5; i++) {
  if (i === 2) continue; // Skip iteration
  if (i === 4) break; // Stop loop
  printf(i);
}

💡 Don't worry! We'll explore each of these in full detail in the next sections.


Liked This Tutorial

Scan QR Code To Leave A Review Or

Click Here To Leave A Review
Scan QR