{"id":742,"date":"2026-10-05T13:00:00","date_gmt":"2026-10-05T07:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=742"},"modified":"2026-11-29T01:29:40","modified_gmt":"2026-11-28T19:59:40","slug":"go-switch-calculator-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/","title":{"rendered":"Go Switch Programs with Output: Calculator, Days and Menus"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go switch programs choose one path out of many, which makes them perfect for menus, calculators and day names. In this post, you will build a working calculator and thirteen more switch programs, each with its exact output. Then you will practice the switch questions that test Go&#8217;s special rules, such as automatic break and <code>fallthrough<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post closes Level 2 of our Go programs series. It builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/\">Go if else programs<\/a>, so read that first. For the theory of <code>switch<\/code>, see <a href=\"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/\">Go conditional statements explained<\/a>. We tested every program on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Switch Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go switch programs compare one value against a list of cases and run the first case that matches. If nothing matches, the optional <code>default<\/code> case runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a lift in a building. You press a floor number, and the lift goes straight to that floor. It does not stop at every floor on the way to check. A <code>switch<\/code> works the same way, jumping straight to the matching case.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Switch Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Long chains of <code>if else<\/code> that check one variable are hard to read. A <code>switch<\/code> makes the same logic short and clear. For example, a menu with six options, a calculator with four operators or a status code with many meanings all fit a switch well.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Menus:<\/strong> pick an action from a numbered list.<\/li>\n\n\n<li><strong>Calculators:<\/strong> run the right operation for <code>+<\/code>, <code>-<\/code>, <code>*<\/code> or <code>\/<\/code>.<\/li>\n\n\n<li><strong>Mapping values:<\/strong> turn a day number into a name, or a code into a message.<\/li>\n\n\n<li><strong>Interviews:<\/strong> questions about <code>fallthrough<\/code> and break rules are common.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Switch Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go checks the cases from top to bottom. It runs the first case that matches and then leaves the switch. Unlike C or Java, you do not need <code>break<\/code>, because Go stops after one case by itself.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-1024x640.png\" alt=\"Go switch programs flowchart showing one value matched against cases and default\" class=\"wp-image-729\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Go compares the value with each case in order, runs the first match, then leaves the switch automatically.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows the kinds of switch you will use in Go switch programs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Kind<\/th><th>Example<\/th><th>Use it for<\/th><\/tr><\/thead><tbody><tr><td>Value switch<\/td><td>switch day { case 1: }<\/td><td>Fixed values<\/td><\/tr><tr><td>Many values per case<\/td><td>case &#8220;Sat&#8221;, &#8220;Sun&#8221;:<\/td><td>Grouping matches<\/td><\/tr><tr><td>No condition<\/td><td>switch { case x &gt; 90: }<\/td><td>Ranges, cleaner than if else<\/td><\/tr><tr><td>With init<\/td><td>switch d := today(); d { }<\/td><td>Keep a variable local<\/td><\/tr><tr><td>Type switch<\/td><td>switch v := x.(type) { }<\/td><td>Checking a value&#8217;s type<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Go Switch Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go switch programs show the main forms of <code>switch<\/code>. We begin with the smallest possible example, so you can see the parts clearly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Traffic Light, the Easiest of the Go Switch Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program looks at one colour and prints what a driver should do.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    light := \"yellow\" \/\/ := creates a new variable and sets its value\n\n    \/\/ switch compares light with each case, from top to bottom.\n    switch light {\n    case \"red\":\n        fmt.Println(\"Stop\")\n    case \"yellow\":\n        fmt.Println(\"Slow down\")\n    case \"green\":\n        fmt.Println(\"Go\")\n    default: \/\/ runs only when no case matches\n        fmt.Println(\"Unknown colour\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Slow down<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go compares <code>light<\/code> with <code>\"red\"<\/code> first, and that does not match. Next it tries <code>\"yellow\"<\/code>, which matches, so it prints &#8220;Slow down&#8221;. Then Go leaves the switch at once, so the <code>\"green\"<\/code> case never runs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Day Name from a Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we put the switch inside a function, so we can call it for many numbers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ dayName turns a number from 1 to 7 into the name of a weekday.\nfunc dayName(dayNumber int) string {\n    switch dayNumber {\n    case 1:\n        return \"Monday\"\n    case 2:\n        return \"Tuesday\"\n    case 3:\n        return \"Wednesday\"\n    case 4:\n        return \"Thursday\"\n    case 5:\n        return \"Friday\"\n    case 6:\n        return \"Saturday\"\n    case 7:\n        return \"Sunday\"\n    default:\n        return \"Invalid day\"\n    }\n}\n\nfunc main() {\n    dayNumbers := []int{1, 5, 7, 9} \/\/ a slice (list) of numbers to test\n\n    \/\/ range gives each item; _ ignores the position we do not need.\n    for _, dayNumber := range dayNumbers {\n        fmt.Println(dayNumber, dayName(dayNumber))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 Monday\n5 Friday\n7 Sunday\n9 Invalid day<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each case returns a name, and <code>default<\/code> catches anything outside 1 to 7. The loop calls <code>dayName<\/code> once for every number in the slice. No <code>break<\/code> is needed anywhere.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Weekday or Weekend<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">One case can list many values, separated by commas.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    days := []string{\"Mon\", \"Sat\", \"Wed\", \"Sun\"}\n\n    for _, day := range days {\n        switch day {\n        case \"Sat\", \"Sun\": \/\/ matches if day is \"Sat\" OR \"Sun\"\n            fmt.Println(day, \"is a weekend\")\n        case \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\":\n            fmt.Println(day, \"is a weekday\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Mon is a weekday\nSat is a weekend\nWed is a weekday\nSun is a weekend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first case matches when the day is either &#8220;Sat&#8221; or &#8220;Sun&#8221;. The second case covers the five working days. So you need only two cases instead of seven.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Vowel Check with a Rune Switch<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    word := \"Golang\"\n\n    \/\/ range over a string gives one letter (a rune) at a time.\n    for _, letter := range word {\n        switch letter {\n        case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U':\n            fmt.Printf(\"%c vowel\\n\", letter) \/\/ %c prints a rune as a letter\n        default:\n            fmt.Printf(\"%c consonant\\n\", letter)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>G consonant\no vowel\nl consonant\na vowel\nn consonant\ng consonant<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop hands each letter of &#8220;Golang&#8221; to the switch. If the letter is in the vowel list, the first case runs. Every other letter falls into <code>default<\/code> and prints &#8220;consonant&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Grade with a Switch Without a Condition<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A switch with no value works like a clean <code>if else<\/code> chain. Each case holds its own condition.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    allMarks := []int{95, 81, 64, 40}\n\n    for _, marks := range allMarks {\n        \/\/ No value after switch, so each case is a true or false check.\n        switch {\n        case marks &gt;= 90:\n            fmt.Println(marks, \"A\")\n        case marks &gt;= 75:\n            fmt.Println(marks, \"B\")\n        case marks &gt;= 50:\n            fmt.Println(marks, \"C\")\n        default:\n            fmt.Println(marks, \"Fail\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>95 A\n81 B\n64 C\n40 Fail<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go runs the first case whose condition is true. For 81, the first check fails, but <code>marks &gt;= 75<\/code> passes. Order still matters, just as in our if else grade program.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Even or Odd with a Switch<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This short program uses the remainder of a division to pick a case.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := []int{4, 7, 10}\n\n    for _, number := range numbers {\n        \/\/ % gives the remainder. An even number has remainder 0 when divided by 2.\n        switch number % 2 {\n        case 0:\n            fmt.Println(number, \"is even\")\n        default:\n            fmt.Println(number, \"is odd\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4 is even\n7 is odd\n10 is even<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The switch checks <code>number % 2<\/code>, which is always 0 or 1. When it is 0, the number is even. Otherwise the <code>default<\/code> case says the number is odd.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Calculator Program with Go Switch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The calculator is the most famous of all Go switch programs. We switch on the operator and handle division by zero.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Simple Calculator<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ calculate applies the operator to two numbers and returns the result or an error.\nfunc calculate(first float64, operator string, second float64) (float64, error) {\n    switch operator {\n    case \"+\":\n        return first + second, nil \/\/ nil means \"no error\"\n    case \"-\":\n        return first - second, nil\n    case \"*\", \"x\":\n        return first * second, nil\n    case \"\/\":\n        if second == 0 {\n            return 0, fmt.Errorf(\"cannot divide by zero\") \/\/ Errorf makes a new error\n        }\n        return first \/ second, nil\n    default:\n        return 0, fmt.Errorf(\"unknown operator %q\", operator) \/\/ %q adds quotes\n    }\n}\n\n\/\/ problem holds one calculation to try.\ntype problem struct {\n    first    float64\n    operator string\n    second   float64\n}\n\nfunc main() {\n    problems := []problem{\n        {12, \"+\", 8}, {9, \"-\", 14}, {6, \"x\", 7},\n        {22, \"\/\", 7}, {5, \"\/\", 0}, {2, \"%\", 3},\n    }\n\n    for _, item := range problems {\n        result, err := calculate(item.first, item.operator, item.second) \/\/ err is the error value\n        if err != nil {\n            fmt.Printf(\"%g %s %g -&gt; error: %v\\n\", item.first, item.operator, item.second, err)\n            continue \/\/ skip to the next problem\n        }\n        fmt.Printf(\"%g %s %g = %.2f\\n\", item.first, item.operator, item.second, result)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>12 + 8 = 20.00\n9 - 14 = -5.00\n6 x 7 = 42.00\n22 \/ 7 = 3.14\n5 \/ 0 -&gt; error: cannot divide by zero\n2 % 3 -&gt; error: unknown operator \"%\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The function returns a result and an error, which is the normal Go style. If <code>err<\/code> is not <code>nil<\/code>, we print the error and move on. <code>%g<\/code> prints numbers without extra zeros, so 12 prints as 12, and <code>%.2f<\/code> shows two decimal places.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Interactive Calculator with User Input<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This version reads expressions like <code>8 * 5<\/code> until the user types <code>q<\/code>. It uses the input tools from our <a href=\"https:\/\/smitabharat.com\/blog\/go-user-input-programs\/\">Go user input programs<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"\n    \"fmt\"\n    \"os\"\n    \"strings\"\n)\n\nfunc main() {\n    scanner := bufio.NewScanner(os.Stdin) \/\/ reads the keyboard line by line\n    fmt.Println(\"Enter a op b (or q to quit)\")\n\n    for scanner.Scan() { \/\/ Scan waits for the next line and returns false at the end\n        line := strings.TrimSpace(scanner.Text())\n        if line == \"q\" {\n            fmt.Println(\"Bye!\")\n            break \/\/ leave the for loop\n        }\n\n        \/\/ Step 1: split the line into number, operator, number.\n        var first, second float64\n        var operator string\n        _, err := fmt.Sscan(line, &amp;first, &amp;operator, &amp;second) \/\/ &amp; lets Sscan fill our variables\n        if err != nil {\n            fmt.Println(\"Format: 8 * 5\")\n            continue\n        }\n\n        \/\/ Step 2: do the maths for the chosen operator.\n        switch operator {\n        case \"+\":\n            fmt.Println(\"=\", first+second)\n        case \"-\":\n            fmt.Println(\"=\", first-second)\n        case \"*\":\n            fmt.Println(\"=\", first*second)\n        case \"\/\":\n            if second == 0 {\n                fmt.Println(\"Cannot divide by zero\")\n            } else {\n                fmt.Println(\"=\", first\/second)\n            }\n        default:\n            fmt.Println(\"Unknown operator\", operator)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We type these lines one by one.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8 * 5\n10 \/ 4\n7 ^ 2\nhello\nq<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a op b (or q to quit)\n= 40\n= 2.5\nUnknown operator ^\nFormat: 8 * 5\nBye!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fmt.Sscan<\/code> splits each line into a number, an operator and a number. If the line has the wrong shape, we print a hint and wait for the next line. When the user types <code>q<\/code>, <code>break<\/code> ends the loop and the program stops.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">More Real-Life Go Switch Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go switch programs show the other switch features.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Days in a Month<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ isLeapYear reports whether February has 29 days in this year.\nfunc isLeapYear(year int) bool {\n    if year%400 == 0 {\n        return true\n    }\n    if year%100 == 0 {\n        return false\n    }\n    return year%4 == 0\n}\n\n\/\/ daysIn returns how many days the month has in the given year.\nfunc daysIn(month, year int) int {\n    switch month {\n    case 4, 6, 9, 11: \/\/ April, June, September, November\n        return 30\n    case 2: \/\/ February depends on the year\n        if isLeapYear(year) {\n            return 29\n        }\n        return 28\n    default:\n        return 31\n    }\n}\n\nfunc main() {\n    fmt.Println(\"Feb 2024:\", daysIn(2, 2024))\n    fmt.Println(\"Feb 2026:\", daysIn(2, 2026))\n    fmt.Println(\"Apr 2026:\", daysIn(4, 2026))\n    fmt.Println(\"Dec 2026:\", daysIn(12, 2026))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Feb 2024: 29\nFeb 2026: 28\nApr 2026: 30\nDec 2026: 31<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The four short months share one case and return 30. February calls <code>isLeapYear<\/code> to choose between 29 and 28. Every other month falls into <code>default<\/code> and gets 31 days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Switch with an Init Statement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Like <code>if<\/code>, a switch can run a short statement first. The variable stays inside the switch.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    input := \"  Start \"\n\n    \/\/ Before the ; we create command. After the ; we switch on it.\n    switch command := strings.ToLower(strings.TrimSpace(input)); command {\n    case \"start\":\n        fmt.Println(\"Starting the server\")\n    case \"stop\":\n        fmt.Println(\"Stopping the server\")\n    default:\n        fmt.Println(\"Unknown command:\", command)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Starting the server<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>TrimSpace<\/code> removes the extra spaces, and <code>ToLower<\/code> makes the text small letters. We clean the input inside the init statement, so &#8221; Start &#8221; still matches &#8220;start&#8221;. You cannot use <code>command<\/code> after the switch ends.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: fallthrough to the Next Case<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fallthrough<\/code> forces Go to also run the next case, without checking it. It is rare, but interviewers like to ask about it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    level := 2\n\n    switch level {\n    case 1:\n        fmt.Println(\"Read access\")\n        fallthrough \/\/ also run the next case\n    case 2:\n        fmt.Println(\"Write access\")\n        fallthrough\n    case 3:\n        fmt.Println(\"Delete access\")\n    case 4:\n        fmt.Println(\"Admin access\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Write access\nDelete access<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Level 2 matches case 2, then <code>fallthrough<\/code> runs case 3 too. Case 3 has no <code>fallthrough<\/code>, so Go stops there and never reaches case 4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Type Switch<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A type switch checks the real type stored in an <code>any<\/code> value. This is useful when data can come in different forms.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ describe tells you what kind of value it was given.\n\/\/ any means the input can hold a value of any type.\nfunc describe(input any) string {\n    \/\/ value gets the matching type inside each case.\n    switch value := input.(type) {\n    case int:\n        return fmt.Sprintf(\"int with value %d\", value)\n    case string:\n        return fmt.Sprintf(\"string of length %d\", len(value))\n    case bool:\n        return fmt.Sprintf(\"bool %t\", value)\n    case nil: \/\/ nil means \"nothing inside\"\n        return \"nil value\"\n    default:\n        return fmt.Sprintf(\"other type %T\", value) \/\/ %T prints the type name\n    }\n}\n\nfunc main() {\n    fmt.Println(describe(42))\n    fmt.Println(describe(\"Golang\"))\n    fmt.Println(describe(true))\n    fmt.Println(describe(nil))\n    fmt.Println(describe(3.5))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>int with value 42\nstring of length 6\nbool true\nnil value\nother type float64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>input.(type)<\/code> asks Go which type is stored inside. Inside each case, <code>value<\/code> already has the matching type, so <code>len(value)<\/code> works for the string. Our <a href=\"https:\/\/smitabharat.com\/blog\/go-type-assertion-type-switch\/\">type assertion and type switch guide<\/a> covers this in depth.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: HTTP Status Messages<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    codes := []int{200, 201, 404, 500, 302}\n\n    for _, code := range codes {\n        switch {\n        case code &gt;= 200 &amp;&amp; code &lt; 300: \/\/ &amp;&amp; means \"and\"\n            fmt.Println(code, \"Success\")\n        case code &gt;= 300 &amp;&amp; code &lt; 400:\n            fmt.Println(code, \"Redirect\")\n        case code &gt;= 400 &amp;&amp; code &lt; 500:\n            fmt.Println(code, \"Client error\")\n        default:\n            fmt.Println(code, \"Server error\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>200 Success\n201 Success\n404 Client error\n500 Server error\n302 Redirect<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each case checks a range of codes with two conditions joined by <code>&amp;&amp;<\/code>. A code like 201 falls in the first range, so it is a success. Anything 500 or above reaches <code>default<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Season from a Month<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    months := []string{\"Jan\", \"Apr\", \"Jul\", \"Oct\"}\n\n    for _, month := range months {\n        var season string \/\/ starts as an empty string\n\n        switch month {\n        case \"Mar\", \"Apr\", \"May\":\n            season = \"Summer\"\n        case \"Jun\", \"Jul\", \"Aug\", \"Sep\":\n            season = \"Monsoon\"\n        case \"Oct\", \"Nov\":\n            season = \"Autumn\"\n        default:\n            season = \"Winter\"\n        }\n        fmt.Println(month, season)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Jan Winter\nApr Summer\nJul Monsoon\nOct Autumn<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The switch stores a name in <code>season<\/code>, and we print it after the switch. Months not listed, such as &#8220;Jan&#8221;, get &#8220;Winter&#8221; from <code>default<\/code>. These are the Indian seasons, which is why monsoon gets four months.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Switch Programs vs if else<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both tools make decisions, so here is when Go switch programs are the better choice and when if else wins.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-1024x640.png\" alt=\"Go switch programs compared with if else chains\" class=\"wp-image-730\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Use switch when one value has many fixed matches, and if else for a few mixed conditions.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>switch<\/th><th>if else<\/th><\/tr><\/thead><tbody><tr><td>Best for<\/td><td>One value, many matches<\/td><td>Few mixed conditions<\/td><\/tr><tr><td>Needs break<\/td><td>No, automatic<\/td><td>Not used<\/td><\/tr><tr><td>Many values in one branch<\/td><td>Yes, case 1, 2, 3<\/td><td>Needs or between checks<\/td><\/tr><tr><td>Type checks<\/td><td>Type switch<\/td><td>Type assertion with ok<\/td><\/tr><tr><td>Readability with 5+ branches<\/td><td>High<\/td><td>Low<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, reach for <code>switch<\/code> when you compare one value against many options. Use <code>if else<\/code> for two or three unrelated conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Switch Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Adding break out of habit:<\/strong> it is not needed, and it can confuse readers.<\/li>\n\n\n<li><strong>Thinking break leaves a loop:<\/strong> inside a switch, <code>break<\/code> only leaves the switch.<\/li>\n\n\n<li><strong>Expecting fallthrough to check the next case:<\/strong> it runs the next case without any check.<\/li>\n\n\n<li><strong>Duplicate cases:<\/strong> the same constant in two cases is a compile error.<\/li>\n\n\n<li><strong>Missing default:<\/strong> without it, unknown values do nothing silently.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Switch Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Always add a default case<\/strong>, even if it only logs an error.<\/li>\n\n\n<li><strong>Group values<\/strong> with commas instead of repeating code.<\/li>\n\n\n<li><strong>Use a switch with no condition<\/strong> for ranges, since it reads better than long if else chains.<\/li>\n\n\n<li><strong>Avoid fallthrough<\/strong> unless the steps truly build on each other.<\/li>\n\n\n<li><strong>Return from cases<\/strong> inside small functions, which keeps the code short.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Switch Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers use short Go switch programs to test the special rules of <code>switch<\/code>. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Rule Questions on Go Switch Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. Do you need break in a Go switch?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Go leaves the switch after the first matching case. You use <code>fallthrough<\/code> when you want the next case to run too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 1\n\n    switch number {\n    case 1:\n        fmt.Println(\"one\")\n        fallthrough\n    case 5:\n        fmt.Println(\"five\")\n    default:\n        fmt.Println(\"default\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>one\nfive<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>fallthrough<\/code> runs case 5 even though <code>number<\/code> is not 5. It does not continue into <code>default<\/code>, because case 5 has no <code>fallthrough<\/code> of its own.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. Why does this program not compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 2\n\n    switch number {\n    case 1:\n        fmt.Println(\"one\")\n    case 1: \/\/ the same value again is not allowed\n        fmt.Println(\"uno\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>duplicate case 1 (constant of type int) in expression switch<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go checks constant cases at compile time and rejects duplicates. This catches copy-paste mistakes early.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. Where can default go in a switch?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anywhere. Go always tries every other case first, and runs <code>default<\/code> only when none match. Still, putting it last is the normal style.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    switch 3 {\n    default: \/\/ written first, but checked last\n        fmt.Println(\"default\")\n    case 3:\n        fmt.Println(\"three\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>three<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Even though <code>default<\/code> comes first, Go tries <code>case 3<\/code> before it. That case matches, so &#8220;three&#8221; prints.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. Can you use fallthrough in the last case?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    switch 1 {\n    case 1:\n        fmt.Println(\"one\")\n        fallthrough \/\/ there is no next case to fall into\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cannot fallthrough final case in switch<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">No. There is no next case to fall into, so the program does not compile. You also cannot use <code>fallthrough<\/code> in a type switch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Output Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    for i := 1; i &lt;= 3; i++ {\n        switch i {\n        case 2:\n            break \/\/ leaves only the switch, not the loop\n        default:\n            fmt.Print(i, \" \")\n        }\n    }\n    fmt.Println(\"done\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 3 done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>break<\/code> only leaves the switch for i = 2. The loop keeps going, so 3 is printed after it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ check prints the number and gives it back, so we can see when it runs.\nfunc check(number int) int {\n    fmt.Println(\"checking\", number)\n    return number\n}\n\nfunc main() {\n    switch 2 {\n    case check(1), check(2), check(3):\n        fmt.Println(\"matched\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>checking 1\nchecking 2\nmatched<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go checks case values from left to right and stops at the first match. So <code>check(3)<\/code> never runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ number is created before the ; and there is no value after it.\n    switch number := 5; {\n    case number &gt; 3:\n        fmt.Println(\"big\")\n        fallthrough\n    case number &gt; 10:\n        fmt.Println(\"huge\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>big\nhuge<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The second case is false, but <code>fallthrough<\/code> runs it anyway. That is why &#8220;huge&#8221; prints even though 5 is not above 10.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    var value any = 10 \/\/ an int stored in an any\n\n    switch value.(type) {\n    case string:\n        fmt.Println(\"string\")\n    case int, int64:\n        fmt.Println(\"some int\")\n    }\n\n    var empty any \/\/ holds nothing yet, so it is nil\n\n    switch empty.(type) {\n    case nil:\n        fmt.Println(\"nil\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>some int\nnil<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A type case can list many types. An interface with nothing inside matches <code>case nil<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    grade := 'B' \/\/ a rune, written with single quotes\n\n    switch grade {\n    case 'A':\n        fmt.Println(\"Excellent\")\n    case 'B', 'C':\n        fmt.Println(\"Well done\")\n    case 'D':\n        fmt.Println(\"Passed\")\n    default:\n        fmt.Println(\"Invalid\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Well done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The grade <code>'B'<\/code> is in the list of the second case. So Go prints &#8220;Well done&#8221; and leaves the switch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. Why does this program not compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 5\n\n    switch number {\n    case \"5\": \/\/ a string, but number is an int\n        fmt.Println(\"five\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cannot convert \"5\" (untyped string constant) to type int<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Every case must match the type of the switch value. Here <code>number<\/code> is an int, and Go cannot turn the string &#8220;5&#8221; into an int, so the case is an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. Can a switch case use a function call or variable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Unlike C, Go cases can be any expression, not only constants. Go evaluates them at run time from top to bottom.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. When should you choose switch over a map lookup?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a map when you only turn one value into another, such as a code into a message. Use a switch when each case runs different logic, such as the steps in a calculator.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    switch {\n    case false:\n        fmt.Println(\"A\")\n    case true:\n        fmt.Println(\"B\")\n    case true:\n        fmt.Println(\"C\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>B<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A switch without a value compares each case with <code>true<\/code>. The second case is the first true one, so only &#8220;B&#8221; prints.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Menus are the most practical Go switch programs. Build one that shows four options: 1 Add item, 2 Remove item, 3 Show items and 4 Exit. Read the choice in a loop and use a switch to handle each option. Hint: keep the items in a slice of strings and use <code>break<\/code> with a label to leave the loop on option 4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/tour\/flowcontrol\/9\">A Tour of Go: Switch<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Switch_statements\">Go spec: switch statements<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/effective_go#switch\">Effective Go: switch<\/a><\/li>\n\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 switch programs run the first matching case and leave automatically, with no break needed.<\/li>\n\n\n<li>One case can list many values, and a switch without a value works like an if else chain.<\/li>\n\n\n<li><code>fallthrough<\/code> runs the next case without checking it.<\/li>\n\n\n<li>A type switch checks the real type inside an <code>any<\/code> value.<\/li>\n\n\n<li>Always add a <code>default<\/code> case so unknown values are handled.<\/li>\n\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\">That completes Level 2 of our Go programs series. Coming soon: Level 3, starting with Go string programs such as reverse a string, palindrome and character count. Until then, revise with the <a href=\"https:\/\/smitabharat.com\/blog\/go-control-flow-questions-part-3\/\">Go control flow interview questions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go switch programs choose one path out of many, which makes them perfect for menus, calculators and day names. In this post, you will&hellip;<\/p>\n","protected":false},"author":1,"featured_media":731,"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":[106],"tags":[96,95,11,104,112],"swapz_series":[],"class_list":["post-742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-programs","tag-go-switch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Switch Programs: Calculator, Days and Menus<\/title>\n<meta name=\"description\" content=\"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.\" \/>\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-switch-calculator-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Switch Programs: Calculator, Days and Menus\" \/>\n<meta property=\"og:description\" content=\"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\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=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Switch Programs with Output: Calculator, Days and Menus\",\"datePublished\":\"2026-10-05T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/\"},\"wordCount\":1938,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-switch-calculator-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\",\"Go Switch\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/\",\"name\":\"Go Switch Programs: Calculator, Days and Menus\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-switch-calculator-programs-featured.png\",\"datePublished\":\"2026-10-05T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:40+00:00\",\"description\":\"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-switch-calculator-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-switch-calculator-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Switch Programs featured image: calculator and switch program output\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-switch-calculator-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Switch Programs with Output: Calculator, Days and Menus\"}]},{\"@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 Switch Programs: Calculator, Days and Menus","description":"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.","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-switch-calculator-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Switch Programs: Calculator, Days and Menus","og_description":"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-05T07:30:00+00:00","article_modified_time":"2026-11-28T19:59:40+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Switch Programs with Output: Calculator, Days and Menus","datePublished":"2026-10-05T07:30:00+00:00","dateModified":"2026-11-28T19:59:40+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/"},"wordCount":1938,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Programs","Go Switch"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/","name":"Go Switch Programs: Calculator, Days and Menus","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png","datePublished":"2026-10-05T07:30:00+00:00","dateModified":"2026-11-28T19:59:40+00:00","description":"Go switch programs with output: a calculator, day names, fallthrough and type switch, plus switch interview questions with real answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-switch-calculator-programs-featured.png","width":2400,"height":1260,"caption":"Go Switch Programs featured image: calculator and switch program output"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Switch Programs with Output: Calculator, Days and Menus"}]},{"@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\/742","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=742"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions"}],"predecessor-version":[{"id":876,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/742\/revisions\/876"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/731"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=742"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}