{"id":738,"date":"2026-10-04T15:00:00","date_gmt":"2026-10-04T09:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=738"},"modified":"2026-11-29T01:29:42","modified_gmt":"2026-11-28T19:59:42","slug":"go-if-else-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/","title":{"rendered":"Go If Else Programs with Output: Even Odd, Leap Year, Grade"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go if else programs teach your code to make decisions, such as &#8220;is this number even?&#8221; or &#8220;did the student pass?&#8221;. In this post, you will write fourteen classic decision programs with their exact output, including even or odd, largest of three, leap year and a grade calculator. After that, you will practice the if\/else interview questions that test Go&#8217;s strict syntax rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on our <a href=\"https:\/\/smitabharat.com\/blog\/go-basic-math-programs\/\">Go basic math programs<\/a>, because most conditions compare numbers. For the theory behind <code>if<\/code>, <code>else<\/code> and <code>switch<\/code>, read <a href=\"https:\/\/smitabharat.com\/blog\/go-conditional-statements-if-else-switch\/\">Go conditional statements explained<\/a>. Every program here was tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go If Else Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go if else programs check a condition and run different code depending on the answer. A condition is any expression that gives <code>true<\/code> or <code>false<\/code>, such as <code>age &gt;= 18<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a traffic signal. If the light is green, you go. Else if it is yellow, you slow down. Else, you stop. Your program does the same thing with <code>if<\/code>, <code>else if<\/code> and <code>else<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go If Else Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every program makes choices, so Go if else programs appear everywhere. For example, an app shows an error if a password is wrong, gives a discount if the cart is big enough, and blocks a payment if the balance is low. These are also the first logic questions in most coding rounds.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Validation:<\/strong> check that input is in range before you use it.<\/li>\n\n\n<li><strong>Business rules:<\/strong> apply tax slabs, discounts and grades.<\/li>\n\n\n<li><strong>Interviews:<\/strong> even\/odd, leap year and largest of three are asked again and again.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go If Else Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Go if else programs, Go checks each condition from top to bottom. It runs the first block whose condition is true and skips the rest. If no condition is true, it runs the <code>else<\/code> block, when there is one.<\/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-if-else-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-1024x640.png\" alt=\"Go if else programs flowchart showing if, else if and else branches\" class=\"wp-image-717\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Go tests each condition in order, runs the first true branch, and falls back to else when nothing matches.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Go has a few strict rules for <code>if<\/code>. The table below sums them up.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Rule<\/th><th>Correct<\/th><th>Wrong<\/th><\/tr><\/thead><tbody><tr><td>Braces are required<\/td><td>if x &gt; 0 { &#8230; }<\/td><td>if x &gt; 0 fmt.Println(x)<\/td><\/tr><tr><td>No brackets needed<\/td><td>if x &gt; 0 {<\/td><td>if (x &gt; 0) { works but gofmt removes them<\/td><\/tr><tr><td>else on the same line as }<\/td><td>} else {<\/td><td>} then else on a new line<\/td><\/tr><tr><td>Condition must be bool<\/td><td>if count &gt; 0 {<\/td><td>if count {<\/td><\/tr><tr><td>Optional short statement<\/td><td>if n := 5; n &gt; 0 {<\/td><td>Using n after the if block<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Number Checks in Go If Else Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s begin with the number checks that every beginner should know. These Go if else programs are the base for all later logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Pass or Fail<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the simplest of all Go if else programs. If the marks are 40 or more, the student passes. Otherwise, the student fails.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    marks := 65 \/\/ := creates a variable and sets its value\n\n    \/\/ if runs the first block when the condition is true\n    if marks &gt;= 40 {\n        fmt.Println(\"Marks:\", marks)\n        fmt.Println(\"Result: Pass\")\n    } else {\n        \/\/ else runs when the condition is false\n        fmt.Println(\"Marks:\", marks)\n        fmt.Println(\"Result: Fail\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Marks: 65\nResult: Pass<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go checks <code>marks &gt;= 40<\/code>, and 65 is bigger than 40, so the condition is true. That is why the first block runs and the <code>else<\/code> block is skipped. Change <code>marks<\/code> to 30 and run it again to see the other branch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Even or Odd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A number is even when it leaves no remainder after division by 2.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := []int{7, 10, 0, -3} \/\/ a slice is a list of values\n\n    \/\/ range gives each number in turn; _ skips its position\n    for _, number := range numbers {\n        if number%2 == 0 { \/\/ % gives the remainder\n            fmt.Println(number, \"is even\")\n        } else {\n            fmt.Println(number, \"is odd\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>7 is odd\n10 is even\n0 is even\n-3 is odd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop takes one number at a time and finds the remainder after dividing by 2. If the remainder is 0, the number is even. For -3, Go gives -3 % 2 = -1, which is not 0, so the else branch runs. That is why we compare with 0, not with 1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Positive, Negative or Zero<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here we need three branches, so we use <code>else if<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := []int{15, -8, 0}\n\n    for _, number := range numbers {\n        if number &gt; 0 {\n            fmt.Println(number, \"is positive\")\n        } else if number &lt; 0 { \/\/ checked only when the first test is false\n            fmt.Println(number, \"is negative\")\n        } else {\n            fmt.Println(number, \"is zero\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>15 is positive\n-8 is negative\n0 is zero<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go first asks if the number is above 0. If not, it asks if it is below 0. When both answers are no, the only choice left is zero, so the <code>else<\/code> block runs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Largest of Three Numbers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is a top interview question. We use <code>&amp;&amp;<\/code>, which means both conditions must be true.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    first, second, third := 42, 87, 63\n\n    \/\/ &amp;&amp; means \"and\": both sides must be true\n    if first &gt;= second &amp;&amp; first &gt;= third {\n        fmt.Println(\"Largest:\", first)\n    } else if second &gt;= first &amp;&amp; second &gt;= third {\n        fmt.Println(\"Largest:\", second)\n    } else {\n        fmt.Println(\"Largest:\", third)\n    }\n\n    \/\/ Go 1.21+ has a built-in max that does the same job\n    fmt.Println(\"Using max():\", max(first, second, third))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Largest: 87\nUsing max(): 87<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program checks if <code>first<\/code> beats both others, then if <code>second<\/code> does. If neither wins, <code>third<\/code> must be the largest. We use <code>&gt;=<\/code> instead of <code>&gt;<\/code>, so equal numbers still give an answer. In real code, the built-in <code>max<\/code> does the same job in one line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Leap Year Check<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A year is a leap year if it divides by 4 but not by 100, or if it divides by 400.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    years := []int{2024, 1900, 2000, 2026}\n\n    for _, year := range years {\n        \/\/ Step 1: divisible by 4 but not by 100 (!= means \"not equal\")\n        normalLeap := year%4 == 0 &amp;&amp; year%100 != 0\n        \/\/ Step 2: or divisible by 400\n        centuryLeap := year%400 == 0\n\n        \/\/ || means \"or\": one true side is enough\n        if normalLeap || centuryLeap {\n            fmt.Println(year, \"is a leap year\")\n        } else {\n            fmt.Println(year, \"is not a leap year\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2024 is a leap year\n1900 is not a leap year\n2000 is a leap year\n2026 is not a leap year<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We split the rule into two named true or false values, so each part is easy to read. Then the <code>if<\/code> checks whether either one is true. 1900 divides by 100 but not by 400, so it is not a leap year. Many people get this one wrong, so test it every time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Divisible by 5 and 11<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program checks two remainders at once with <code>&amp;&amp;<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    numbers := []int{55, 110, 25}\n\n    for _, number := range numbers {\n        if number%5 == 0 &amp;&amp; number%11 == 0 {\n            fmt.Println(number, \"is divisible by both 5 and 11\")\n        } else {\n            fmt.Println(number, \"is not divisible by both\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>55 is divisible by both 5 and 11\n110 is divisible by both 5 and 11\n25 is not divisible by both<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A number divides evenly when its remainder is 0. The <code>&amp;&amp;<\/code> makes sure both remainders are 0. 25 divides by 5 but not by 11, so it goes to the <code>else<\/code> branch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Real-Life Go If Else Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go if else programs use the same ideas for everyday rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Grade Calculator<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The order of conditions matters here. We check the highest range first.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    allMarks := []int{92, 76, 58, 35}\n\n    for _, marks := range allMarks {\n        var grade string \/\/ starts as an empty string \"\"\n\n        if marks &gt;= 90 {\n            grade = \"A\"\n        } else if marks &gt;= 75 {\n            grade = \"B\"\n        } else if marks &gt;= 50 {\n            grade = \"C\"\n        } else {\n            grade = \"Fail\"\n        }\n        fmt.Printf(\"Marks %d: Grade %s\\n\", marks, grade) \/\/ %d prints a number, %s a string\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Marks 92: Grade A\nMarks 76: Grade B\nMarks 58: Grade C\nMarks 35: Grade Fail<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For each mark, Go walks down the chain and stops at the first true check. Since 92 also passes <code>marks &gt;= 75<\/code>, putting that check first would give the wrong grade. Always go from the strictest rule to the loosest.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Voting Eligibility with a Short Statement<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Go lets you run a short statement before the condition. The variable you create lives only inside the <code>if<\/code> and <code>else<\/code> blocks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    birthYear := 2010\n\n    \/\/ The part before ; runs first and creates age.\n    \/\/ The part after ; is the condition.\n    if age := 2026 - birthYear; age &gt;= 18 {\n        fmt.Println(\"Age\", age, \"- can vote\")\n    } else {\n        yearsLeft := 18 - age\n        fmt.Println(\"Age\", age, \"- can vote in\", yearsLeft, \"years\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Age 16 - can vote in 2 years<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, Go works out <code>age<\/code> as 16. Then it checks <code>age &gt;= 18<\/code>, which is false, so the <code>else<\/code> block runs. <code>age<\/code> exists in both branches, but after the closing brace it is gone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Vowel or Consonant<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program checks a letter. <code>strings.ContainsRune<\/code> saves us from writing five <code>||<\/code> checks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"unicode\" \/\/ unicode has helpers for letters and digits\n)\n\nfunc main() {\n    \/\/ A rune is a single character, written in single quotes\n    letters := []rune{'a', 'G', 'E', '7'}\n\n    for _, letter := range letters {\n        lower := unicode.ToLower(letter) \/\/ 'G' becomes 'g'\n\n        if !unicode.IsLetter(letter) { \/\/ ! means \"not\"\n            fmt.Printf(\"%c is not a letter\\n\", letter) \/\/ %c prints a character\n        } else if strings.ContainsRune(\"aeiou\", lower) {\n            fmt.Printf(\"%c is a vowel\\n\", letter)\n        } else {\n            fmt.Printf(\"%c is a consonant\\n\", letter)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a is a vowel\nG is a consonant\nE is a vowel\n7 is not a letter<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program rules out anything that is not a letter, such as &#8216;7&#8217;. Next, it looks for the small letter inside &#8220;aeiou&#8221;. <code>unicode.ToLower<\/code> makes the check work for capital letters too.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Profit or Loss<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program compares two prices and reports the result.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    costPrice := 1200.0\n    sellingPrice := 1350.0\n\n    if sellingPrice &gt; costPrice {\n        profit := sellingPrice - costPrice\n        profitPercent := profit \/ costPrice * 100\n        fmt.Printf(\"Profit: %.2f (%.1f%%)\\n\", profit, profitPercent) \/\/ %% prints a % sign\n    } else if sellingPrice &lt; costPrice {\n        loss := costPrice - sellingPrice\n        fmt.Printf(\"Loss: %.2f\\n\", loss)\n    } else {\n        fmt.Println(\"No profit, no loss\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Profit: 150.00 (12.5%)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go compares the selling price with the cost price. Here it is higher, so the program finds the profit and its percentage. Each branch only calculates what it needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Free Delivery Check<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Many shops give free delivery above a certain cart value. Go if else programs handle rules like this one easily.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    cartTotals := []int{350, 499, 500, 1200} \/\/ cart values in rupees\n    freeDeliveryLimit := 500\n    deliveryCharge := 40\n\n    for _, cartTotal := range cartTotals {\n        if cartTotal &gt;= freeDeliveryLimit {\n            fmt.Println(\"Cart\", cartTotal, \"- free delivery, pay\", cartTotal)\n        } else {\n            amountToPay := cartTotal + deliveryCharge\n            fmt.Println(\"Cart\", cartTotal, \"- delivery\", deliveryCharge, \"pay\", amountToPay)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Cart 350 - delivery 40 pay 390\nCart 499 - delivery 40 pay 539\nCart 500 - free delivery, pay 500\nCart 1200 - free delivery, pay 1200<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For each cart, Go compares the total with the limit of 500. A cart of 500 or more skips the charge. Smaller carts go to the <code>else<\/code> block, which adds 40 rupees. Look at 499 and 500 to see how <code>&gt;=<\/code> treats the exact limit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Triangle Check and Type<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Three sides make a triangle only if each pair adds up to more than the third side.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    sideA, sideB, sideC := 5, 5, 8\n\n    \/\/ Step 1: can these sides form a triangle at all?\n    if sideA+sideB &lt;= sideC || sideA+sideC &lt;= sideB || sideB+sideC &lt;= sideA {\n        fmt.Println(\"Not a valid triangle\")\n    } else if sideA == sideB &amp;&amp; sideB == sideC { \/\/ Step 2: all three equal\n        fmt.Println(\"Equilateral triangle\")\n    } else if sideA == sideB || sideB == sideC || sideA == sideC { \/\/ Step 3: two equal\n        fmt.Println(\"Isosceles triangle\")\n    } else {\n        fmt.Println(\"Scalene triangle\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Isosceles triangle<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program rejects sides that cannot meet. Then it checks whether all three sides match, and then whether two match. Here 5 and 5 are equal, so the triangle is isosceles.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: ATM Withdrawal Rules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Real rules often need nested checks. Here we use early returns instead, which keeps the code flat.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ withdraw checks the ATM rules and prints the result\nfunc withdraw(balance int, amount int) {\n    if amount &lt;= 0 {\n        fmt.Println(\"Enter a valid amount\")\n        return \/\/ stop here and leave the function\n    }\n    if amount%100 != 0 {\n        fmt.Println(\"Amount must be in multiples of 100\")\n        return\n    }\n    if amount &gt; balance {\n        fmt.Println(\"Insufficient balance\")\n        return\n    }\n    balanceLeft := balance - amount\n    fmt.Println(\"Please collect\", amount, \"- balance left:\", balanceLeft)\n}\n\nfunc main() {\n    withdraw(5000, 1500)\n    withdraw(5000, 250)\n    withdraw(5000, 9000)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Please collect 1500 - balance left: 3500\nAmount must be in multiples of 100\nInsufficient balance<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each check returns as soon as it fails. Only an amount that passes all three checks reaches the last two lines. This &#8220;guard clause&#8221; style is very common in Go code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Character Type Check<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program sorts each character of a string into a group.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"unicode\"\n)\n\nfunc main() {\n    \/\/ range over a string gives one character (rune) at a time\n    for _, character := range \"aZ5 #\" {\n        if unicode.IsUpper(character) {\n            fmt.Printf(\"%q is uppercase\\n\", character) \/\/ %q prints it in quotes\n        } else if unicode.IsLower(character) {\n            fmt.Printf(\"%q is lowercase\\n\", character)\n        } else if unicode.IsDigit(character) {\n            fmt.Printf(\"%q is a digit\\n\", character)\n        } else if unicode.IsSpace(character) {\n            fmt.Printf(\"%q is a space\\n\", character)\n        } else {\n            fmt.Printf(\"%q is a symbol\\n\", character)\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>'a' is lowercase\n'Z' is uppercase\n'5' is a digit\n' ' is a space\n'#' is a symbol<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop takes each character and tries the checks in order. The <code>unicode<\/code> package answers each question for us. Anything that fails every check ends up as a symbol.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go If Else Programs vs switch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you have many branches that compare one value, <code>switch<\/code> is often cleaner. The diagram and table below compare the two.<\/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-if-else-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-1024x640.png\" alt=\"Go if else programs comparison of if else chains and switch statements\" class=\"wp-image-718\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Use if else for ranges and mixed conditions, and switch for many fixed values.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>if else<\/th><th>switch<\/th><\/tr><\/thead><tbody><tr><td>Best for<\/td><td>Ranges and mixed conditions<\/td><td>Many fixed values<\/td><\/tr><tr><td>Readability with 5+ cases<\/td><td>Gets long<\/td><td>Stays clean<\/td><\/tr><tr><td>Needs break<\/td><td>No<\/td><td>No, Go breaks automatically<\/td><\/tr><tr><td>Short statement<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Example<\/td><td>marks &gt;= 90<\/td><td>case &#8220;Mon&#8221;, &#8220;Tue&#8221;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use if else for checks like &#8220;marks above 75&#8221;, and switch for menus or day names. We build switch programs later in this level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go If Else Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>else on a new line:<\/strong> Go needs <code>} else {<\/code> on one line, or the code does not compile.<\/li>\n\n\n<li><strong>Non-bool conditions:<\/strong> <code>if count {<\/code> fails, because Go does not treat numbers as true or false.<\/li>\n\n\n<li><strong>Wrong order of ranges:<\/strong> check <code>&gt;= 90<\/code> before <code>&gt;= 75<\/code>, or every high score gets the lower grade.<\/li>\n\n\n<li><strong>Using = instead of ==:<\/strong> <code>if marks = 5<\/code> is a compile error, which protects you from a classic bug.<\/li>\n\n\n<li><strong>Deep nesting:<\/strong> many levels of <code>if<\/code> are hard to read, so return early instead.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go If Else Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Return early<\/strong> for errors, so the main path stays on the left edge.<\/li>\n\n\n<li><strong>Use the short statement form<\/strong> to keep temporary variables out of the rest of the function.<\/li>\n\n\n<li><strong>Order conditions from most to least specific<\/strong>, so every value lands in the right branch.<\/li>\n\n\n<li><strong>Let gofmt remove brackets<\/strong> around conditions, because Go style does not use them.<\/li>\n\n\n<li><strong>Switch to switch<\/strong> when one value has many possible matches.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go If Else Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers use Go if else programs to test both logic and syntax. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax Questions on Go If Else Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. 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    if number &gt; 3 {\n        fmt.Println(\"big\")\n    }\n    else {\n        fmt.Println(\"small\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>syntax error: unexpected keyword else, expected }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go adds a semicolon at the end of a line that ends with <code>}<\/code>. So the <code>if<\/code> statement ends there, and the lonely <code>else<\/code> is an error. Always write <code>} else {<\/code> on one line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. 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    count := 3\n    if count { \/\/ count is an int, not true or false\n        fmt.Println(\"has items\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>non-boolean condition in if statement<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In Go, an <code>if<\/code> condition must be a bool. Write <code>if count &gt; 0<\/code> instead. Go never treats 0 as false like C does.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. Does Go have a ternary operator like a ? b : c?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. The Go team left it out to keep code easy to read. Use a short <code>if else<\/code> instead, or write a small helper function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. 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    if number := 10; number &gt; 5 {\n        fmt.Println(\"inside:\", number)\n    }\n    fmt.Println(\"outside:\", number) \/\/ number does not exist here\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>undefined: number<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A variable made in the <code>if<\/code> short statement only lives inside that <code>if<\/code> and its <code>else<\/code> blocks. Outside, it does not exist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. Can you write an if without braces for one line?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Braces are always required in Go, even for a single statement. This rule removes a whole class of bugs found in other languages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Go If Else Programs: Logic and 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\n\/\/ check prints its name and always returns false\nfunc check(name string) bool {\n    fmt.Println(\"checking\", name)\n    return false\n}\n\nfunc main() {\n    if check(\"A\") &amp;&amp; check(\"B\") {\n        fmt.Println(\"both true\")\n    }\n    if check(\"C\") || check(\"D\") {\n        fmt.Println(\"one true\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>checking A\nchecking C\nchecking D<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>&amp;&amp;<\/code> stops as soon as the left side is false, so &#8220;B&#8221; is never checked. <code>||<\/code> only stops when the left side is true, so both &#8220;C&#8221; and &#8220;D&#8221; run. This is called short-circuit evaluation.<\/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\nfunc main() {\n    value := 10\n    \/\/ This := makes a NEW value that exists only inside the if\n    if value := 5; value &gt; 3 {\n        fmt.Println(\"inner value:\", value)\n    }\n    fmt.Println(\"outer value:\", value)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>inner value: 5\nouter value: 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>value<\/code> inside the <code>if<\/code> is a new variable that hides the outer one. This is called shadowing. The outer <code>value<\/code> keeps its old number, 10.<\/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    score := 75\n    if score &gt; 50 {\n        fmt.Println(\"pass\")\n    } else if score &gt; 70 {\n        fmt.Println(\"distinction\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>pass<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first true branch wins, and Go skips the rest. Since 75 &gt; 50 is true, &#8220;distinction&#8221; never prints, even though it is also true.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you compare two strings without caring about case?<\/strong><\/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 := \"YES\"\n    \/\/ EqualFold compares two strings and ignores capital letters\n    if strings.EqualFold(input, \"yes\") {\n        fmt.Println(\"confirmed\")\n    }\n    fmt.Println(input == \"yes\") \/\/ == cares about case\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>confirmed\nfalse<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>==<\/code> is case-sensitive, so &#8220;YES&#8221; is not equal to &#8220;yes&#8221;. <code>strings.EqualFold<\/code> ignores case.<\/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    first, second := 3, 7\n    if first &gt; second {\n        fmt.Println(\"first is bigger\")\n    } else if first == second {\n        fmt.Println(\"equal\")\n    } else if second-first &gt; 3 {\n        fmt.Println(\"far\")\n    } else {\n        fmt.Println(\"near\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>far<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first two checks are false. Then 7 &#8211; 3 is 4, which is greater than 3, so &#8220;far&#8221; prints.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. How do you check if a number is between 1 and 100?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Combine two comparisons with <code>&amp;&amp;<\/code>: <code>if number &gt;= 1 &amp;&amp; number &lt;= 100<\/code>. Go does not allow the math style <code>1 &lt;= number &lt;= 100<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. 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 := 0\n    if number &gt; 0 {\n        fmt.Println(\"positive\")\n    }\n    if number == 0 {\n        fmt.Println(\"zero\")\n    }\n    if number &gt;= 0 {\n        fmt.Println(\"not negative\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>zero\nnot negative<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">These are three separate <code>if<\/code> statements, not one chain. So Go checks all three, and two of them are true.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Clean Code Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. How can you write an if inside a function that returns a value?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ sign returns a word that describes the number\nfunc sign(number int) string {\n    if number &gt; 0 {\n        return \"positive\"\n    }\n    if number &lt; 0 {\n        return \"negative\"\n    }\n    return \"zero\"\n}\n\nfunc main() {\n    fmt.Println(sign(9), sign(-2), sign(0))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>positive negative zero<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There is no <code>else<\/code> here, because each <code>return<\/code> leaves the function. Go linters often suggest this style.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. How do you check an error with if in one line?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the short statement form, as in <code>if err := doWork(); err != nil { ... }<\/code>. Here <code>err<\/code> is the error value, and <code>nil<\/code> means &#8220;no error&#8221;. This pattern appears in almost every Go file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. 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 name string \/\/ a string starts as \"\" (empty)\n    if name == \"\" {\n        fmt.Println(\"name is empty\")\n    }\n\n    var ok bool \/\/ ok is a common Go name for a true or false result; it starts as false\n    if !ok {\n        fmt.Println(\"ok is false\")\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>name is empty\nok is false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Uninitialized variables get zero values. A string starts as &#8220;&#8221; and a bool starts as false, so both checks pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. Should you compare floats with == in an if?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually no, because of rounding errors. Check that the difference is tiny instead, as in <code>if math.Abs(first-second) &lt; 1e-9<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. 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    temperature := 31\n    if temperature &gt; 30 {\n        fmt.Println(\"hot\")\n        \/\/ An if inside another if is called a nested if\n        if temperature &gt; 40 {\n            fmt.Println(\"very hot\")\n        } else {\n            fmt.Println(\"but bearable\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>hot\nbut bearable<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The outer condition is true, so Go enters it. Inside, 31 is not above 40, so the inner <code>else<\/code> runs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task mixes the ideas from all the Go if else programs above. Write a program that takes an electricity bill in units and prints the amount: the first 100 units cost 5 rupees each, the next 100 cost 7 each, and anything above 200 costs 10 each. Hint: use if else from the highest slab down and add the parts.<\/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\/5\">A Tour of Go: If<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#If_statements\">Go spec: if statements<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/effective_go#if\">Effective Go: if<\/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 if else programs run the first branch whose condition is true.<\/li>\n\n\n<li>Conditions must be bool, braces are required and <code>} else {<\/code> must be on one line.<\/li>\n\n\n<li>The short statement form, <code>if x := f(); x &gt; 0<\/code>, keeps variables local.<\/li>\n\n\n<li><code>&amp;&amp;<\/code> and <code>||<\/code> stop early, which is called short-circuit evaluation.<\/li>\n\n\n<li>Order range checks from strictest to loosest, and return early to avoid deep nesting.<\/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\">Next, your programs learn to repeat work. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-loop-programs\/\">Go loop programs with output<\/a>, where we print tables, factorials and Fibonacci numbers. For the theory of loops, see <a href=\"https:\/\/smitabharat.com\/blog\/go-for-loops-examples\/\">Go for loops explained with examples<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go if else programs teach your code to make decisions, such as &#8220;is this number even?&#8221; or &#8220;did the student pass?&#8221;. In this post,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":719,"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,26,95,11,104],"swapz_series":[],"class_list":["post-738","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-conditional-statements","tag-go-interview-questions","tag-go-lang","tag-go-programs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go If Else Programs: Even Odd, Leap Year, Grade<\/title>\n<meta name=\"description\" content=\"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with 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-if-else-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go If Else Programs: Even Odd, Leap Year, Grade\" \/>\n<meta property=\"og:description\" content=\"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-04T09:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-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=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go If Else Programs with Output: Even Odd, Leap Year, Grade\",\"datePublished\":\"2026-10-04T09:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/\"},\"wordCount\":2127,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-if-else-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Conditional Statements\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/\",\"name\":\"Go If Else Programs: Even Odd, Leap Year, Grade\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-if-else-programs-featured.png\",\"datePublished\":\"2026-10-04T09:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:42+00:00\",\"description\":\"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-if-else-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-if-else-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go If Else Programs featured image: output of even odd, leap year and grade checks\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-if-else-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go If Else Programs with Output: Even Odd, Leap Year, Grade\"}]},{\"@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 If Else Programs: Even Odd, Leap Year, Grade","description":"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with 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-if-else-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go If Else Programs: Even Odd, Leap Year, Grade","og_description":"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-04T09:30:00+00:00","article_modified_time":"2026-11-28T19:59:42+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go If Else Programs with Output: Even Odd, Leap Year, Grade","datePublished":"2026-10-04T09:30:00+00:00","dateModified":"2026-11-28T19:59:42+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/"},"wordCount":2127,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-featured.png","keywords":["Beginner","Go Conditional Statements","Go Interview Questions","Go Lang","Go Programs"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/","name":"Go If Else Programs: Even Odd, Leap Year, Grade","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-featured.png","datePublished":"2026-10-04T09:30:00+00:00","dateModified":"2026-11-28T19:59:42+00:00","description":"Go if else programs with output: even or odd, largest of three, leap year, grades and more, plus if else interview questions with answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-if-else-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-if-else-programs-featured.png","width":2400,"height":1260,"caption":"Go If Else Programs featured image: output of even odd, leap year and grade checks"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go If Else Programs with Output: Even Odd, Leap Year, Grade"}]},{"@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\/738","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=738"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"predecessor-version":[{"id":872,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions\/872"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/719"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=738"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}