DEV Community

Firdavs Mukhsimov
Firdavs Mukhsimov

Posted on

While Loop

While Loop
a) while loop va do while loop o'rtasidagi
farqni tushuntiring.

1. while sikli
Siklning bajarilish sharti: while sikli 
birinchi navbatda shartni tekshiradi va 
shart to'g'ri(true) bo'lsa, sikl tanasi bajariladi.

Sintaksis:

while (shart)
{
    // Sikl tanasi
}
2. do-while sikli
Siklning bajarilish sharti: do-while siklida 
dastlab sikl tanasi bir marta bajariladi, keyin 
esa shart tekshiriladi. Shart to'g'ri (true) 
bo'lsa, sikl takroran bajariladi.

Sintaksis:

do
{
    // Sikl tanasi
} while (shart);
Enter fullscreen mode Exit fullscreen mode

b) Quyidagi while loop qanday ishlayd va natijasi
nima bo'ladi?

int x = 0;
while(x < 3)
{
    Console.WriteLine(x);
    x++;
}
int tipida x nomli o'zgaruvchi yaratib, uni 0 
ga tenglaymiz. while() shartiga x kichik 
bo'lsa 3 dan degan shartni beramiz. shart 
3 martta to'g'ri ishlaydi. Javob: 0, 1, 2.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)