C# dasturlash tili tohirov behzod nasriddinovich


case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break


Download 0.66 Mb.
bet5/5
Sana18.10.2023
Hajmi0.66 Mb.
#1707226
1   2   3   4   5
Bog'liq
С sharp dasturlash tili

case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break;

case 5: Console.WriteLine("Friday"); break;

case 6: Console.WriteLine("Saturday"); break;

case 7: Console.WriteLine("Sunday"); break;

} //Outputs "Thursday" (day 4)

C# while takrorlash operatori:

C# while takrorlash operatori:

Belgilangan while shart mavjud bo'lganda, sikl kod bloki bo'ylab aylanadi True. Sintaksisi:

while (condition)

{ code block to be executed }

Quyidagi misolda, (i) o'zgaruvchisi 5 dan kichik bo'lsa, sikldagi kod qayta-qayta ishlaydi:

int i = 0;

while (i < 5)

{ Console.WriteLine(i);

i++; }

Eslatma!: Shartda ishlatiladigan o'zgaruvchini oshirishni unutmang, aks holda tsikl hech qachon tugamaydi!

C# Switch tanlash operatori. Misol :

  • C# Switch tanlash operatori. Misol :
  • int day = 4; switch (day)

    {

    case 1: Console.WriteLine("Monday"); break;

    case 2: Console.WriteLine("Tuesday"); break;

    case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break;

    case 5: Console.WriteLine("Friday"); break;

    case 6: Console.WriteLine("Saturday"); break;

    case 7: Console.WriteLine("Sunday"); break;

    } //Outputs "Thursday" (day 4)

Do/While sikli- bu kodni bir marta bajaradi, so'ngra shart to'g'ri bo'lsa, siklni takrorlaydi.

Do/While sikli- bu kodni bir marta bajaradi, so'ngra shart to'g'ri bo'lsa, siklni takrorlaydi.

Sintaksis:

do

{ // code block to be executed }

while (condition);

Misol:

int i = 0; do { Console.WriteLine(i); i++; }

while (i < 5);

Eslatma!: Shartda ishlatiladigan o'zgaruvchini oshirishni unutmang, aks holda tsikl hech qachon tugamaydi!

For –Parametrli takrorlash operatori:

For –Parametrli takrorlash operatori:

Takrorlanishlar soni aniq bo’lsa, for dan foydalaning:

Sintaksis

for (statement 1; statement 2; statement 3)

{ code block to be executed }

Misol:

for (int i = 0; i < 5; i++)

{ Console.WriteLine(i); }

Yana bir misol

for (int i = 0; i <= 10; i = i + 2)

{ Console.WriteLine(i); }


Download 0.66 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling