30.while Loop (Advanced)
a) while loopdan foydalanib, foydalanuvchi ragam kiritgancha loopni davom ettirish kodini yozing (masalan, 0 kiritilganda loop tugaydi).
b) Quyidagi kodning natijasi nima bo'ladi?
int x = 10;
while (x > 0)
{
Console. WriteLine(x);
x -= 2;
}
Javoblari:
a)
int num;
while(true)
{
num = int.Parse(Console.ReadLine());
if(num == 0)
{
break; // 0 kiritilganda loop to'xtaydi
}
}
b) 10
8
6
4
2
Top comments (0)