{"id":130,"date":"2026-03-30T09:00:00","date_gmt":"2026-03-30T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=130"},"modified":"2026-10-10T21:20:35","modified_gmt":"2026-10-10T15:50:35","slug":"go-conditional-statements-if-else-switch","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/","title":{"rendered":"Go Conditional Statements: If, Else and Switch Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go conditional statements let your program make decisions, like showing a discount only to members. In this post, you will learn if, else, else if and switch. Each idea comes with a short example that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every condition here uses the comparison and logical symbols from the last lesson. So if <code>&gt;=<\/code> or <code>&amp;&amp;<\/code> feels new, first read <a href=\"https:\/\/smitabharat.com\/blog\/go-operators-examples\/\">operators in Go with simple examples<\/a>. You will also use the values from <a href=\"https:\/\/smitabharat.com\/blog\/go-variables-constants-data-types\/\">variables, constants and data types<\/a>. And if Go is not set up yet, follow the guide to <a href=\"https:\/\/smitabharat.com\/blog\/install-go-first-program\/\">install Go and run your first program<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Conditional Statements?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A conditional statement runs a block of code only when a condition is true. Here, a condition is any check that gives back true or false, such as <code>age &gt;= 18<\/code>. A block is the code between curly braces <code>{ }<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a traffic signal. If the light is green, you drive. Otherwise, you stop and wait. Go conditional statements work the same way, because they pick one path based on a simple yes or no answer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Basic if Statement<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>age := 20\n\nif age &gt;= 18 {\n\tfmt.Println(\"You can vote\")\n}\n\/\/ You can vote<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First comes the word <code>if<\/code>, then the condition, and then the block. Notice that Go needs no brackets around the condition. However, the curly braces are always required, even for a single line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding else and else if<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Often you want a second path for when the condition is false. For that, add <code>else<\/code>. Then, to check more than two cases, add <code>else if<\/code> in between.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score := 72\n\nif score &gt;= 90 {\n\tfmt.Println(\"Grade A\")\n} else if score &gt;= 60 {\n\tfmt.Println(\"Pass\")\n} else {\n\tfmt.Println(\"Fail\")\n}\n\/\/ Pass<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go checks each condition from top to bottom. As soon as one is true, it runs that block and skips the rest. So for a score of 72, the first check fails, the second one passes, and Go prints Pass. The diagram below shows this flow step by step.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-diagram-1024x640.png\" alt=\"Go Conditional Statements diagram showing how Go checks an if, else if, else chain for score 72\" class=\"wp-image-132\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-diagram.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The chain stops at the first true condition, and then the program continues.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Conditional Statements with a Short Statement<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go lets you run a small statement right before the condition, separated by a semicolon. As a result, the variable you create lives only inside the if and else blocks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if n := len(\"Smita\"); n &gt; 3 {\n\tfmt.Println(\"Long name with\", n, \"letters\")\n}\n\/\/ Long name with 5 letters<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <code>n<\/code> exists only inside this if. This keeps your code tidy, since the variable cannot leak into the rest of the function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Checking Errors with if<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You will see this pattern in almost every Go program. Many functions return a value and an error, so you check the error before you use the value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>num, err := strconv.Atoi(\"25a\")\n\nif err != nil {\n\tfmt.Println(\"Not a valid number\")\n} else {\n\tfmt.Println(num * 2)\n}\n\/\/ Not a valid number<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The function <code>strconv.Atoi<\/code> turns text into a number. Because &#8220;25a&#8221; is not a number, <code>err<\/code> is not nil, which means something went wrong. We will cover errors in detail later in this series.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Switch: Cleaner Go Conditional Statements<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A long chain of else if quickly becomes hard to read. In that case, a switch is cleaner. It compares one value against a list of cases. Think of a lift that stops only at the floor you pressed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>day := \"Tuesday\"\n\nswitch day {\ncase \"Saturday\", \"Sunday\":\n\tfmt.Println(\"Weekend\")\ncase \"Monday\":\n\tfmt.Println(\"Start of the week\")\ndefault:\n\tfmt.Println(\"Working day\")\n}\n\/\/ Working day<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>default<\/code> case runs when no other case matches. Also, Go stops after the first matching case on its own. So unlike Java or C, you never need to write <code>break<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Many Values in One Case<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Look again at <code>case \"Saturday\", \"Sunday\"<\/code> above. A comma lets one case match several values. This saves you from repeating the same code twice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Switch with No Condition<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>temp := 34\n\nswitch {\ncase temp &gt;= 30:\n\tfmt.Println(\"Hot\")\ncase temp &gt;= 20:\n\tfmt.Println(\"Warm\")\ndefault:\n\tfmt.Println(\"Cold\")\n}\n\/\/ Hot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When you leave out the value after switch, each case becomes its own true or false check. In short, this is a neat way to write a long if else chain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The fallthrough Keyword<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>level := 1\n\nswitch level {\ncase 1:\n\tfmt.Println(\"Level 1 done\")\n\tfallthrough\ncase 2:\n\tfmt.Println(\"Level 2 done\")\ncase 3:\n\tfmt.Println(\"Level 3 done\")\n}\n\/\/ Level 1 done\n\/\/ Level 2 done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>fallthrough<\/code> keyword tells Go to also run the next case, without checking it. You will rarely need it, but now you know what it does.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">If Else vs Switch: Which Go Conditional Statements to Use?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Situation<\/th><th>Best choice<\/th><\/tr><\/thead><tbody><tr><td>One or two simple checks<\/td><td>if or if else<\/td><\/tr><tr><td>Checking an error after a function call<\/td><td>if err != nil<\/td><\/tr><tr><td>One value with many possible matches<\/td><td>switch value<\/td><\/tr><tr><td>Many range checks, like grades or temperature<\/td><td>switch with no condition<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Both kinds of Go conditional statements give the same result, so pick the one that reads more clearly. As a simple rule, use switch once you have three or more branches.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Conditional Statements<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>syntax error: unexpected keyword else, expected }<\/td><td>The else sits on a new line.<\/td><td>Write } else { on the same line.<\/td><\/tr><tr><td>non-boolean condition in if statement<\/td><td>Here x is a number, not true or false.<\/td><td>Compare it, for example if x &gt; 0.<\/td><\/tr><tr><td>syntax error: unexpected name fmt, expected {<\/td><td>The curly braces are missing.<\/td><td>Always wrap the block in { }.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The first error surprises most beginners. Go adds an invisible semicolon at the end of a line that ends with <code>}<\/code>, so a lonely else breaks the code. Also, these small rules show up in interviews, so practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they are always accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/tour\/flowcontrol\/5\">A Tour of Go: If statements<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#If_statements\">Go spec: If statements<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Switch_statements\">Go spec: Switch statements<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/effective_go#control-structures\">Effective Go: Control structures<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go conditional statements run code only when a condition is true.<\/li>\n\n\n\n<li>Use if, else if and else for a few checks, with no brackets but always with braces.<\/li>\n\n\n\n<li>A short statement like if n := len(s); n &gt; 3 keeps the variable inside the if.<\/li>\n\n\n\n<li>Switch stops at the first match on its own, so you never write break.<\/li>\n\n\n\n<li>Keep } else { on one line to avoid the most common beginner error.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now your programs can make decisions. Next, we will make them repeat work with loops, so you can process a whole list in a few lines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coming soon: Go For Loops Explained with Examples<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go conditional statements let your program make decisions, like showing a discount only to members. In this post, you will learn if, else, else&hellip;<\/p>\n","protected":false},"author":1,"featured_media":191,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[26,11,23,21],"swapz_series":[],"class_list":["post-130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-conditional-statements","tag-go-lang","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Conditional Statements: If, Else and Switch<\/title>\n<meta name=\"description\" content=\"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Conditional Statements: If, Else and Switch\" \/>\n<meta property=\"og:description\" content=\"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-30T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Conditional Statements: If, Else and Switch Explained\",\"datePublished\":\"2026-03-30T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/\"},\"wordCount\":937,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-conditional-statements-if-else-switch-featured-1.png\",\"keywords\":[\"Go Conditional Statements\",\"Go Lang\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/\",\"name\":\"Go Conditional Statements: If, Else and Switch\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-conditional-statements-if-else-switch-featured-1.png\",\"datePublished\":\"2026-03-30T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:35+00:00\",\"description\":\"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-conditional-statements-if-else-switch-featured-1.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-conditional-statements-if-else-switch-featured-1.png\",\"width\":1200,\"height\":630,\"caption\":\"Go Conditional Statements featured image: cards showing if, else and switch with simple examples\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-conditional-statements-if-else-switch\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Conditional Statements: If, Else and Switch Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Conditional Statements: If, Else and Switch","description":"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/","og_locale":"en_US","og_type":"article","og_title":"Go Conditional Statements: If, Else and Switch","og_description":"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.","og_url":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-03-30T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:35+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Conditional Statements: If, Else and Switch Explained","datePublished":"2026-03-30T03:30:00+00:00","dateModified":"2026-10-10T15:50:35+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/"},"wordCount":937,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png","keywords":["Go Conditional Statements","Go Lang","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/","url":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/","name":"Go Conditional Statements: If, Else and Switch","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png","datePublished":"2026-03-30T03:30:00+00:00","dateModified":"2026-10-10T15:50:35+00:00","description":"Learn Go conditional statements with simple examples: if, else, else if, switch and fallthrough, plus the common mistakes beginners make.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-conditional-statements-if-else-switch-featured-1.png","width":1200,"height":630,"caption":"Go Conditional Statements featured image: cards showing if, else and switch with simple examples"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Conditional Statements: If, Else and Switch Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":3,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions\/135"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/191"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=130"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}