DEV Community

Sunnat Qayumov
Sunnat Qayumov

Posted on

2 2 2 2 2

30.while Loop (Advanced)

a) while loopdan foydalanib, foydalanuvchi ragam kiritgancha loopni davom ettirish kodini yozing (masalan, 0 kiritilganda loop tugaydi).

int num;

while(true)
{
    num = int.Parse(Console.ReadLine());

    if(num == 0)
    {
        break; // 0 kiritilganda loop to'xtaydi
    }
}
Enter fullscreen mode Exit fullscreen mode

b)Quyidagi kodning natijasi nima bo'ladi?

int x = 10;
while (x > 0)
{
    Console.WriteLine(x);
    x -= 2;
}
Enter fullscreen mode Exit fullscreen mode

Javob:

10
8
6
4
2
Enter fullscreen mode Exit fullscreen mode

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