DEV Community

Cover image for Loops(for,while,do while)
umida5
umida5

Posted on

Loops(for,while,do while)

C# tilida while va do while sikllari o'rtasidagi farq:

  1. while sikli:
  2. Ushbu sikl shartni tekshiradi va agar shart true bo'lsa, ichidagi kodni bajaradi. Agar shart dastlab false bo'lsa, kod hech qachon bajarilmaydi.
while (shart)
{
    // bajariladigan kod
}

Enter fullscreen mode Exit fullscreen mode
  1. do while sikli:
  2. Ushbu sikl avval kodni bajaradi, so'ngra shartni tekshiradi. Shuning uchun, kod kamida bir marta bajariladi, hatto shart false bo'lsa ham.
do
{
    // bajariladigan kod
}
while (shart);

Enter fullscreen mode Exit fullscreen mode

Farqi:

  • while sikli shartni avval tekshiradi, do while esa kodni avval bajaradi, keyin shartni tekshiradi.

*For Loop

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

Enter fullscreen mode Exit fullscreen mode

Bu misolda for loop 0 dan 4 gacha bo'lgan sonlarni chiqaradi.

  • int i = 0 - loop boshlanishida i o'zgaruvchisi 0 ga tenglanadi.
  • i < 5 - loop davom etishi uchun shart. i 5 dan kichik bo'lishi kerak.
  • i++ - har bir increment dan so'ng i ning qiymatini 1 ga oshadi.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay