Switch statement haqida

Assalomu aleykum! Bugungi postimiz switch statement haqida bo’ladi.
Switch – ifga o’xshash bo’lgan gramatika bo’lib , ifdan soddaroq tuzilgan. Ularning asosiy farqlaridan biri shuki , if orqali hamma datatiplarni ishlatish mumkin bo’lsa, switch stateme…


This content originally appeared on DEV Community and was authored by Munisa Kuranbekova

Assalomu aleykum! Bugungi postimiz switch statement haqida bo'ladi.
Switch - ifga o'xshash bo'lgan gramatika bo'lib , ifdan soddaroq tuzilgan. Ularning asosiy farqlaridan biri shuki , if orqali hamma datatiplarni ishlatish mumkin bo'lsa, switch statementda faqat int va chardn foydalanish mumkin.
Switch expression
{
case Constant 1:
statement 1
break;
case Constant 2:
statement 2
break;
case Constant 3:
statement 3
break;
}

Yuqorida yozilgan strukturamiz switchning syntaxi hisoblanadi.Kodga o'tadigan bo'lsak:

#include <iostream>

using namespace std;

int main()
{  

    int son;
    cin>> son;

switch(son)
{
case 1:
cout << " One " << endl;

case 2:
cout << " Two " << endl;

case 3:
cout << " Three " << endl;

case 4:
cout << " Four " << endl;

 default:
cout << "none" << endl;   

    return 0;
}

Ushbu kodni run qiladigan bo'lsak consolega kodimizga to'g'ri kelgan sonlarni chop etadi. To'g'ri javobning bir o'zi kerak bo'lsa , har bitta cout komandasining tagidan break; deb yozib chiqishimiz zarur.


This content originally appeared on DEV Community and was authored by Munisa Kuranbekova


Print Share Comment Cite Upload Translate Updates
APA

Munisa Kuranbekova | Sciencx (2024-11-02T12:55:16+00:00) Switch statement haqida. Retrieved from https://www.scien.cx/2024/11/02/switch-statement-haqida/

MLA
" » Switch statement haqida." Munisa Kuranbekova | Sciencx - Saturday November 2, 2024, https://www.scien.cx/2024/11/02/switch-statement-haqida/
HARVARD
Munisa Kuranbekova | Sciencx Saturday November 2, 2024 » Switch statement haqida., viewed ,<https://www.scien.cx/2024/11/02/switch-statement-haqida/>
VANCOUVER
Munisa Kuranbekova | Sciencx - » Switch statement haqida. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/02/switch-statement-haqida/
CHICAGO
" » Switch statement haqida." Munisa Kuranbekova | Sciencx - Accessed . https://www.scien.cx/2024/11/02/switch-statement-haqida/
IEEE
" » Switch statement haqida." Munisa Kuranbekova | Sciencx [Online]. Available: https://www.scien.cx/2024/11/02/switch-statement-haqida/. [Accessed: ]
rf:citation
» Switch statement haqida | Munisa Kuranbekova | Sciencx | https://www.scien.cx/2024/11/02/switch-statement-haqida/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.