DEV Community

Sunnat Qayumov
Sunnat Qayumov

Posted on

2 2 2 2 2

29.for Loop (Advanced)

a) for loopda break operatori ganday ishlatiladi? Misol keltiring.

break operatori for, while yoki boshqa sikl (loop) ichida 
ishlatilganda, siklni to‘xtatadi va sikldan tashqariga chiqadi. Bu 
operator ma'lum bir shart bajarilganda siklni to‘xtatish uchun 
ishlatiladi.
Enter fullscreen mode Exit fullscreen mode

b) Quyidagi kod natijasini tushuntiring:

for(int i = 0; i < 10; i++)
{
    if(i == 7)
    {    
        break;
    }
    Console.WriteLine(i);
}
Enter fullscreen mode Exit fullscreen mode

Agar i == 7 bo‘lsa, break operatori ishlaydi va sikl darhol to‘xtaydi.

Natija esa:
0
1
2
3
4
5
6
Enter fullscreen mode Exit fullscreen mode

i = 7 bo‘lganda break operatori ishlagani uchun loop to‘xtaydi va 7 dan keyingi qiymatlar ekranga chiqarilmaydi.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay