{"id":9848,"date":"2023-10-10T12:19:41","date_gmt":"2023-10-10T12:19:41","guid":{"rendered":"https:\/\/adelnasim.com\/docs\/courses\/cpp-tutorial\/selection-statement-switch-statement\/"},"modified":"2024-04-07T01:19:22","modified_gmt":"2024-04-07T01:19:22","slug":"selection-statement-switch-statement","status":"publish","type":"docs","link":"https:\/\/adelnasim.com\/ar\/docs\/courses\/cpp-tutorial\/selection-statement-switch-statement\/","title":{"rendered":"\u0627\u0644\u062c\u0645\u0644 \u0627\u0644\u0634\u0631\u0637\u064a\u0629 - \u062c\u0645\u0644\u0629 switch"},"content":{"rendered":"<p data-sourcepos=\"1:1-1:152\">\u062a\u064f\u0633\u062a\u062e\u062f\u0645 \u0627\u0644\u062c\u0645\u0644 \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629 \u0641\u064a \u0644\u063a\u0629 C++ \u0644\u0644\u062a\u062d\u0643\u0645 \u0641\u064a \u062a\u062f\u0641\u0642 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c. \u0625\u0646\u0647\u0627 \u062a\u0633\u0645\u062d \u0644\u0643 \u0628\u062a\u0646\u0641\u064a\u0630 \u0645\u062c\u0645\u0648\u0639\u0627\u062a \u0645\u062e\u062a\u0644\u0641\u0629 \u0645\u0646 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0628\u0646\u0627\u0621\u064b \u0639\u0644\u0649 \u0634\u0631\u0648\u0637 \u0645\u062e\u062a\u0644\u0641\u0629.<\/p>\n<p data-sourcepos=\"3:1-3:45\">\u0647\u0646\u0627\u0643 \u0646\u0648\u0639\u0627\u0646 \u0631\u0626\u064a\u0633\u064a\u0627\u0646 \u0644\u0644\u062c\u0645\u0644 \u0627\u0644\u0634\u0637\u0631\u064a\u0651\u0629 \u0641\u064a \u0644\u063a\u0629 C++ \u0647\u0645\u0627:<\/p>\n<ul data-sourcepos=\"5:1-7:0\">\n<li data-sourcepos=\"5:1-5:100\"><strong>\u062c\u0645\u0644\u0629 if \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629:<\/strong>\u00a0\u0627\u0644\u0640\u00a0<code>if<\/code>\u00a0\u062a\u0633\u0645\u062d \u0628\u062a\u0646\u0641\u064a\u0630 \u0645\u062c\u0645\u0648\u0639\u0629 \u0645\u0646 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0625\u0630\u0627 \u0643\u0627\u0646 \u0627\u0644\u0634\u0631\u0637 \u0635\u062d\u064a\u062d\u064b\u0627.<\/li>\n<li data-sourcepos=\"6:1-7:0\"><strong>\u062c\u0645\u0644\u0629 switch:<\/strong>\u00a0\u0627\u0644\u0640\u00a0<code>switch<\/code>\u00a0\u062a\u0633\u0645\u062d \u0628\u062a\u062d\u062f\u064a\u062f \u0648\u0627\u062d\u062f\u0629 \u0645\u0646 \u0645\u062c\u0645\u0648\u0639\u0627\u062a \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0627\u0644\u0645\u062a\u0639\u062f\u062f\u0629 \u0644\u062a\u0646\u0641\u064a\u0630\u0647\u0627 \u0628\u0646\u0627\u0621\u064b \u0639\u0644\u0649 \u0642\u064a\u0645\u0629 \u0627\u0644\u062a\u0639\u0628\u064a\u0631.<\/li>\n<\/ul>\n<p>\u0642\u0645\u0646\u0627 \u0628\u0634\u0631\u062d \u062c\u0645\u0644\u0629 if \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629 \u062a\u062d\u062a \u0627\u0644\u0639\u0646\u0648\u0627\u0646<a href=\"https:\/\/adelnasim.com\/ar\/docs\/courses\/cpp-tutorial\/selection-statement-9820\/\">\u0627\u0644\u062c\u0645\u0644 \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629 - \u062c\u0645\u0644\u0629 if \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629<\/a>\u0648\u0627\u0644\u0622\u0646 \u0633\u0646\u0634\u0631\u062d \u0627\u0644\u0645\u0632\u064a\u062f \u0639\u0646 \"\u062c\u0645\u0644\u0629 switch \u0627\u0644\u0634\u0631\u0637\u064a\u0651\u0629\".<\/p>\n<div class=\"logo-gutter ng-tns-c3907565777-124 ng-star-inserted\">\n<div class=\"gutter ng-star-inserted\"><\/div>\n<\/div>\n<div tabindex=\"0\" aria-hidden=\"true\"><\/div>\n<div class=\"response-container-content ng-tns-c3907565777-124\">\n<div class=\"response-content ng-trigger ng-trigger-responsePopulation ng-tns-c3907565777-124\">\n<div class=\"markdown markdown-main-panel\" dir=\"ltr\">\n<p data-sourcepos=\"1:1-1:195\">\u062c\u0645\u0644\u0629 switch \u0641\u064a \u0644\u063a\u0629 C++ \u062a\u062a\u062d\u0643\u0645 \u0641\u064a \u0627\u0644\u0633\u0645\u0627\u062d \u0628\u062a\u0646\u0641\u064a\u0630 \u0645\u062c\u0645\u0648\u0639\u0627\u062a \u0645\u062e\u062a\u0644\u0641\u0629 \u0645\u0646 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0628\u0646\u0627\u0621\u064b \u0639\u0644\u0649 \u0642\u064a\u0645\u0629 \u0645\u0648\u062c\u0648\u062f\u0629 \u0641\u064a \u062a\u0639\u0628\u064a\u0631 \u062d\u0633\u0627\u0628\u064a \u0623\u0648 \u0645\u0646\u0637\u0642\u064a. \u0628\u0646\u0627\u0621 \u0627\u0644\u062c\u0645\u0644\u0629 \u0627\u0644\u0639\u0627\u0645 \u0644\u062c\u0645\u0644\u0629 switch \u0647\u0648 \u0643\u0645\u0627 \u064a\u0644\u064a:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block\">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">switch (expression) {\r\n  case value1:\r\n    \/\/ code to execute if expression equals value1\r\n  case value2:\r\n    \/\/ code to execute if expression equals value2\r\n  ...\r\n  default:\r\n    \/\/ code to execute if expression does not equal any of the values in the case statements\r\n}<\/pre>\n<\/div>\n<p data-sourcepos=\"15:1-15:417\">\u0627\u0644\u0640 <code>expression<\/code> \u064a\u0645\u0643\u0646 \u0623\u0646 \u064a\u0643\u0648\u0646 \u0623\u064a \u062a\u0639\u0628\u064a\u0631 \u0635\u062d\u064a\u062d. \u062d\u064a\u062b \u062a\u0642\u0648\u0645 \u062c\u0645\u0644\u0629 switch \u0628\u062a\u0642\u064a\u064a\u0645\u0647 \u0627\u0644\u0640( <code>expression<\/code> ) \u0648\u0645\u0642\u0627\u0631\u0646\u062a\u0647 \u0628\u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u0645\u0630\u0643\u0648\u0631\u0629 \u0641\u064a \u062c\u0645\u0644\u0629 \u0627\u0644\u062d\u0627\u0644\u0629 <code>case<\/code> \u062d\u064a\u062b \u0625\u0630\u0627 \u0643\u0627\u0646 <code>expression<\/code> \u064a\u0633\u0627\u0648\u064a \u0648\u0627\u062d\u062f\u0629 \u0645\u0646 \u0627\u0644\u0642\u064a\u0645 \u0627\u0644\u0645\u0648\u062c\u0648\u062f\u0629 \u0641\u064a \u062c\u0645\u0644 \u0627\u0644\u062d\u0627\u0644\u0629 <code>case<\/code> \u0633\u064a\u062a\u0645 \u062a\u0646\u0641\u064a\u0630 \u0645\u062c\u0645\u0648\u0639\u0629 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0627\u0644\u0645\u0648\u062c\u0648\u062f\u0629 \u062f\u0627\u062e\u0644 \u062c\u0645\u0644\u0629 \u0627\u0644\u062d\u0627\u0644\u0629 <code>case<\/code> . \u0623\u0645\u0627 \u0625\u0630\u0627 \u0643\u0627\u0646 \u0627\u0644\u0640 <code>expression<\/code> \u0644\u0627 \u064a\u0633\u0627\u0648\u064a \u0623\u064a \u0645\u0646 \u0627\u0644\u0642\u064a\u0645 \u0627\u0644\u0645\u0648\u062c\u0648\u062f\u0629 \u0641\u064a \u062c\u0645\u0644 \u0627\u0644\u062d\u0627\u0644\u0629 <code>case<\/code> \u060c \u0641\u0625\u0646 \u0645\u062c\u0645\u0648\u0639\u0629 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u062f\u0627\u062e\u0644 \u0627\u0644\u0640 <code>default<\/code> \u0633\u064a\u062a\u0645 \u062a\u0646\u0641\u064a\u0630\u0647\u0627.<\/p>\n<p data-sourcepos=\"17:1-17:41\">\u0641\u064a\u0645\u0627 \u064a\u0644\u064a \u0645\u062b\u0627\u0644 \u0644\u062c\u0645\u0644\u0629 switch:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block\">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    int x = 0;\r\n    cin &gt;&gt; x;\r\n    \r\n    switch (x)\r\n    {\r\n        case 1: cout &lt;&lt; \"case #1\" &lt;&lt; endl;\r\n            break;\r\n        case 2: cout &lt;&lt; \"case #2\" &lt;&lt; endl;\r\n            break;\r\n        case 3: cout &lt;&lt; \"case #3\" &lt;&lt; endl;\r\n            break;\r\n        default:\r\n            cout &lt;&lt; \"Out of range\" &lt;&lt; endl;\r\n            break;\r\n    }\r\n    \r\n    return 0;\r\n}<\/pre>\n<\/div>\n<p data-sourcepos=\"17:1-17:41\">\u064a\u0645\u0643\u0646\u0643 \u0623\u064a\u0636\u064b\u0627 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0627\u0644\u0623\u062d\u0631\u0641 \u0628\u062f\u0644\u0627\u064b \u0645\u0646 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 \u0641\u064a \u062c\u0645\u0644\u0629 switch. \u0639\u0644\u0649 \u0633\u0628\u064a\u0644 \u0627\u0644\u0645\u062b\u0627\u0644:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block\">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n    char c = 'a';\r\n    \r\n    switch (c)\r\n    {\r\n        case 'a': cout &lt;&lt; \"case #a\" &lt;&lt; endl;\r\n            break;\r\n        case 'b': cout &lt;&lt; \"case #b\" &lt;&lt; endl;\r\n            break;\r\n        default:\r\n            cout &lt;&lt; \"Out of range\" &lt;&lt; endl;\r\n            break;\r\n    }\r\n    \r\n    return 0;\r\n}<\/pre>\n<\/div>\n<p data-sourcepos=\"17:1-17:41\">\u0627\u0644\u0645\u062e\u0631\u062c\u0627\u062a:<\/p>\n<div class=\"wp-block-codemirror-blocks code-block\">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:false,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">case #a<\/pre>\n<\/div>\n<p data-sourcepos=\"17:1-17:41\"><strong>\u062a\u0630\u0643\u0631!<br \/>\n<\/strong>\u0625\u0646 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u062d\u0631\u0641 \u0643\u0628\u064a\u0631 \u0645\u062b\u0644 \"A\" \u0641\u064a \u0627\u0644\u0645\u062b\u0627\u0644 \u0627\u0644\u0633\u0627\u0628\u0642 \u0644\u0627 \u064a\u0634\u0628\u0647 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u062d\u0631\u0641 \u0635\u063a\u064a\u0631 \u0645\u062b\u0644 \"a\". \u0627\u0646\u0647\u0645 \u0644\u064a\u0633\u0648 \u0646\u0641\u0633 \u0627\u0644\u0634\u064a\u0621!<\/p>\n<p data-sourcepos=\"51:1-51:39\"><strong>\u0645\u0645\u064a\u0632\u0627\u062a \u0625\u0633\u062a\u062e\u062f\u0627\u0645 \u062c\u0645\u0644\u0629 switch:<\/strong><\/p>\n<p data-sourcepos=\"53:1-53:199\">\u064a\u0645\u0643\u0646 \u0623\u0646 \u062a\u0643\u0648\u0646 \u062c\u0645\u0644 switch \u0623\u0643\u062b\u0631 \u0643\u0641\u0627\u0621\u0629 \u0645\u0646 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0633\u0644\u0633\u0644\u0629 \u0645\u0646 \u062c\u0645\u0644 if\u060c \u062e\u0627\u0635\u0629 \u0639\u0646\u062f\u0645\u0627 \u064a\u0643\u0648\u0646 \u0647\u0646\u0627\u0643 \u0627\u0644\u0639\u062f\u064a\u062f \u0645\u0646 \u0627\u0644\u062d\u0627\u0644\u0627\u062a \u0627\u0644\u0645\u062e\u062a\u0644\u0641\u0629. \u064a\u0645\u0643\u0646 \u0644\u062c\u0645\u0644 switch \u0623\u064a\u0636\u064b\u0627 \u0623\u0646 \u062a\u062c\u0639\u0644 \u0627\u0644\u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0645\u062c\u064a\u0629 \u0627\u0644\u062e\u0627\u0635\u0629 \u0628\u0643 \u0623\u0643\u062b\u0631 \u0642\u0627\u0628\u0644\u064a\u0629 \u0644\u0644\u0642\u0631\u0627\u0621\u0629 \u0648\u0627\u0644\u0635\u064a\u0627\u0646\u0629.<\/p>\n<p data-sourcepos=\"55:1-55:14\"><strong>\u0627\u0644\u062e\u0644\u0627\u0635\u0629<\/strong><\/p>\n<p data-sourcepos=\"57:1-57:165\">\u062a\u0639\u062f \u062c\u0645\u0644\u0629 switch \u0623\u062f\u0627\u0629 \u0642\u0648\u064a\u0629 \u0644\u0644\u062a\u062d\u0643\u0645 \u0641\u064a \u062a\u062f\u0641\u0642 \u0628\u0631\u0646\u0627\u0645\u062c C++ \u0627\u0644\u062e\u0627\u0635 \u0628\u0643. \u0648\u0645\u0646 \u062e\u0644\u0627\u0644 \u0641\u0647\u0645 \u0643\u064a\u0641\u064a\u0629 \u0627\u0633\u062a\u062e\u062f\u0627\u0645\u0647\u0627\u060c \u064a\u0645\u0643\u0646\u0643 \u0643\u062a\u0627\u0628\u0629 \u062a\u0639\u0644\u064a\u0645\u0627\u062a \u0628\u0631\u0645\u062c\u064a\u0629 \u0623\u0643\u062b\u0631 \u0643\u0641\u0627\u0621\u0629 \u0648\u0645\u0648\u062b\u0648\u0642\u064a\u0629.<\/p>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Selection statements in C++ are used to control the flow of a program. They allow you to execute different blocks of code based on different conditions. The two main selection statements in C++ are: if statement:\u00a0The\u00a0if\u00a0statement allows you to execute a block of code if a condition is true. switch statement:\u00a0The\u00a0switch\u00a0statement allows you to select [&hellip;]<\/p>","protected":false},"author":3,"featured_media":0,"parent":2744,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-9848","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/9848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/comments?post=9848"}],"version-history":[{"count":7,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/9848\/revisions"}],"predecessor-version":[{"id":9856,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/9848\/revisions\/9856"}],"up":[{"embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/docs\/2744"}],"wp:attachment":[{"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/media?parent=9848"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/adelnasim.com\/ar\/wp-json\/wp\/v2\/doc_tag?post=9848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}