break Keyword

The break statement immediately exits the nearest enclosing loop (for, while, do) or a switch.
Control continues with the first statement after that construct.


Syntax

break;

Examples

// for লুপ আগে থামানো
for (let i = 1; i <= 10; i++) {
  যদি (i === 5) {
    কনসোল.সতর্ক("৫ এ থামছে");
    থামুন;
  }
  কনসোল.লগ("i =", i);
}

// প্রথম মেলামেশা পেলে থামাও
const সংখ্যা = [3, 9, 12, 7];
for (const n of সংখ্যা) {
  যদি (n % 3 === 0 && n > 10) {
    কনসোল.লগ("পাওয়া গেছে:", n);
    থামুন;
  }
}

// while লুপে থামুন
let গণনা = 0;
while (true) {
  যদি (++গণনা === 3) থামুন;
  কনসোল.লগ("লুপিং", গণনা);
}

// switch ব্লকে থামুন
const গ্রেড = "B";
বিকল্প (গ্রেড) {
  অবস্থা "A":
    কনসোল.লগ("দারুণ");
    থামুন;
  অবস্থা "B":
    কনসোল.লগ("ভালো");
    থামুন;
  অন্যথায়:
    কনসোল.লগ("অজানা");
}

Notes

  • break affects only the innermost loop or switch.
  • Use clear conditions to avoid accidental infinite loops that rely on break.
  • Prefer early return inside functions when you need to exit multiple levels of logic.