{"id":1141,"date":"2022-08-30T15:13:04","date_gmt":"2022-08-30T15:13:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/the-absence-of-brace-syntax-in-switch-cases-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:04","modified_gmt":"2022-08-30T15:13:04","slug":"the-absence-of-brace-syntax-in-switch-cases-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/the-absence-of-brace-syntax-in-switch-cases-collection-of-common-programming-errors\/","title":{"rendered":"The absence of brace syntax in switch cases?-Collection of common programming errors"},"content":{"rendered":"<p>There is no language I&#8217;m aware of that requires braces as part of the <code>switch<\/code>\/<code>case<\/code> syntax. It wouldn&#8217;t necessarily make much sense, as braces typically introduce &#8220;block scope&#8221;, which is conventionally <em>not<\/em> in play between <code>case<\/code> statements.<\/p>\n<p>It may interest you to know, however, that in some languages (like C++) you can use braces <em>as part of the case statement<\/em> (rather than as part of the switch\/case syntax itself) to introduce your own bounded scope:<\/p>\n<pre><code>switch (x) {\n  case a:\n    {\n       ...\n       break;\n    }\n}\n<\/code><\/pre>\n<p>Sometimes a C++ compiler will require you to do this, most notably when you declare variables inside a <code>case<\/code> statement.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:32:00. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>There is no language I&#8217;m aware of that requires braces as part of the switch\/case syntax. It wouldn&#8217;t necessarily make much sense, as braces typically introduce &#8220;block scope&#8221;, which is conventionally not in play between case statements. It may interest you to know, however, that in some languages (like C++) you can use braces as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1141"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1141\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}