29.For Loop

asilbek_ibragimov_a0c27cc

asilbek ibragimov

Posted on October 14, 2024

29.For Loop

29.for Loop (Advanced)
a) for loopda break operatori ganday ishlatiladi? Misol keltiring.
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

Javoblari:
a) 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.
b) Agar i == 7 bo‘lsa, break operatori ishlaydi va sikl darhol to‘xtaydi. Natija esa:
0
1
2
3
4
5
6
i = 7 bo‘lganda break operatori ishlagani uchun loop to‘xtaydi va 7 dan keyingi qiymatlar ekranga chiqarilmaydi.

💖 💪 🙅 🚩
asilbek_ibragimov_a0c27cc
asilbek ibragimov

Posted on October 14, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related