Loops(Advanced)

umida5 - Oct 14 - - Dev Community

break va continue operatorlari

for siklida break va continue operatorlari yordamida siklni to‘xtatish yoki keyingi iteratsiyaga o‘tish mumkin.

  • break siklni butunlay to‘xtatadi:
for(int i = 0; i < 10; i++)
{
    if(i == 5)
    {
        break; // 5 ga yetganda sikl to‘xtaydi
    }
    Console.WriteLine(i);
}
Enter fullscreen mode Exit fullscreen mode
  • continue siklni to‘xtatmay, faqat keyingi iteratsiyaga o‘tadi:
for(int i = 0; i < 5; i++)
{
    if(i == 2)
    {
        continue; // 2 ni chiqarib yuboradi
    }
    Console.WriteLine(i);
}
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .