{"id":331,"date":"2023-01-18T14:34:31","date_gmt":"2023-01-18T14:34:31","guid":{"rendered":"https:\/\/aipsacademy.com\/blogs\/?p=331"},"modified":"2023-01-18T14:34:32","modified_gmt":"2023-01-18T14:34:32","slug":"switch-statement-in-c-language","status":"publish","type":"post","link":"https:\/\/aipsacademy.com\/blogs\/2023\/01\/18\/switch-statement-in-c-language\/","title":{"rendered":"Switch Statement in C++ Language"},"content":{"rendered":"\n<p><strong>Switch statement is used to execute different set of statements according to different values of a single variable or an expression.<\/strong><\/p>\n\n\n\n<p>It is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Conditional_(computer_programming)\">conditional statement<\/a> and used for decision making when we have multiple options. it is an alternative of ladder if-else.<\/p>\n\n\n\n<p><em>Each condition is specified with &#8216;case&#8217; and each  case can have a break statement.<\/em><\/p>\n\n\n\n<p><strong>&#8216;break&#8217; is used to exit form case.<\/strong><\/p>\n\n\n\n<p>Multiple cases can have a single &#8216;break&#8217; statement.<\/p>\n\n\n\n<p>when none of the case is satisfied then  &#8216;default&#8217; block is executed.<\/p>\n\n\n\n<p><strong>It is similar to ladder if-els<\/strong>e<\/p>\n\n\n\n<p><strong>Syntax <\/strong><\/p>\n\n\n\n<p><strong>switch<\/strong>(variable \/expression)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p><strong>case<\/strong> value<strong>1<\/strong>:<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>break<\/strong>;<\/p>\n\n\n\n<p><strong>case<\/strong> value2:<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>break<\/strong>;<\/p>\n\n\n\n<p><strong>case<\/strong> value3<strong>:<\/strong><\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>break<\/strong>;<\/p>\n\n\n\n<p><strong>case<\/strong> value4:<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>break<\/strong>;<\/p>\n\n\n\n<p><strong>case<\/strong> value n:<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>break<\/strong>;<\/p>\n\n\n\n<p><strong>default:<\/strong><\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<p><strong>break;<\/strong><\/p>\n\n\n\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Switch statement is used to execute different set of statements according to different values of a single variable or an expression. It is a conditional statement and used for decision making when we have multiple options. it is an alternative of ladder if-else. Each condition is specified with &#8216;case&#8217; and each case can have a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":332,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,3,9,7,8,6],"tags":[],"class_list":["post-331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-11th-computer-science","category-12th-computer-science","category-bca","category-cbse-12th-computer-science","category-cbse","category-jac-12th-computer-science","category-jac"],"_links":{"self":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/comments?post=331"}],"version-history":[{"count":1,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/331\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/331\/revisions\/333"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/media\/332"}],"wp:attachment":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/media?parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/categories?post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/tags?post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}