DEV Community

Zahro
Zahro

Posted on

6. Loops(for, while, do while)

a) for loopning sintaksisi qanday? Misol keltiring.

Sintaksis:

for (int variable = son; variable < son; variable++)
{
// code block
}

Misol:

for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}

b) while loop va do while loop o'rtasidagi farq nima?

while loop: Shart dastlab tekshiriladi, agar shart to'g'ri bo'lsa, sikl bajariladi.

do while loop: Sikl hech bo'lmaganda bir marta ishlaydi, shundan keyin shart tekshiriladi.

c) Quyidagi kodning natijasini ayting:

int i = 0;

while (i < 5) 
{
    Console.WriteLine(i);
    i++;
}

Enter fullscreen mode Exit fullscreen mode

Natija:

0
1
2
3
4

Top comments (0)