DEV Community

BUTTSAN
BUTTSAN

Posted on

1 1 1 1 1

assalomu aleykum 28.08.24 biz c++ da nabatagi darsimizni otdik

  1. bu switch switchBajariladigan ko'plab kod bloklaridan birini tanlash uchun bayonotdan foydalaning . ex.
switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Enter fullscreen mode Exit fullscreen mode

Bu shunday ishlaydi:

Ifoda switchbir marta baholanadi
Ifodaning qiymati har birining qiymatlari bilan taqqoslanadicase
Agar mos keladigan bo'lsa, tegishli kod bloki bajariladi
breakva kalit so'zlari defaultixtiyoriy bo'lib, ular keyinchalik ushbu bobda tasvirlanadi
Quyidagi misolda ish kuni nomini hisoblash uchun ish kuni raqamidan foydalaniladi:
ex.

int day = 4;
switch (day) {
  case 1:
    cout << "Monday";
    break;
  case 2:
    cout << "Tuesday";
    break;
  case 3:
    cout << "Wednesday";
    break;
  case 4:
    cout << "Thursday";
    break;
  case 5:
    cout << "Friday";
    break;
  case 6:
    cout << "Saturday";
    break;
  case 7:
    cout << "Sunday";
    break;
}
// Outputs "Thursday" (day 4)

Enter fullscreen mode Exit fullscreen mode

Tanaffus kalit so'zi
C++ kalit so'zga yetganda break , u switch blokidan chiqib ketadi.

Bu blok ichida ko'proq kod va holatlar testini bajarishni to'xtatadi.

Gugurt topilib, ish tugagach, tanaffus vaqti keldi. Ko'proq test o'tkazishga hojat yo'q.
2.break
C++ Break
You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch statement.

The break statement can also be used to jump out of a loop.

This example jumps out of the loop when i is equal to 4:

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    break;
  }
  cout << i << "\n";
}
Enter fullscreen mode Exit fullscreen mode

Agar belgilangan shart yuzaga kelsa, bayonot continuebitta iteratsiyani (siklda) buzadi va tsikldagi keyingi iteratsiya bilan davom etadi.

Ushbu misol 4 qiymatini o'tkazib yuboradi:
\

for (int i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  }
  cout << i << "\n";
}
Enter fullscreen mode Exit fullscreen mode

breakShuningdek , va continuewhile sikllaridan ham foydalanishingiz mumkin :

int i = 0;
while (i < 10) {
  if (i == 4) {
    i++;
    continue;
  }
  cout << i << "\n";
  i++;
}
Enter fullscreen mode Exit fullscreen mode

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

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

Okay