DEV Community

umida5
umida5

Posted on

Loops(Advanced)

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

Top comments (0)