{"id":741,"date":"2026-10-05T11:00:00","date_gmt":"2026-10-05T05:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=741"},"modified":"2026-11-29T01:29:40","modified_gmt":"2026-11-28T19:59:40","slug":"go-pattern-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/","title":{"rendered":"Go Pattern Programs: Star, Number and Pyramid Patterns"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go pattern programs print shapes such as triangles, pyramids and diamonds using stars, numbers or letters. They look simple, but they test exactly how well you control nested loops, which is why interviewers love them. In this post, you will write fourteen pattern programs with their exact output, and learn one trick that makes every pattern easier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need the nested loops from our <a href=\"https:\/\/smitabharat.com\/blog\/go-loop-programs\/\">Go loop programs<\/a> post, so read it first if loops are new to you. We also use <code>strings.Repeat<\/code> from our <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings guide<\/a>. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Pattern Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go pattern programs use loops to print characters in rows and columns, so the output forms a shape. The outer loop picks the row, and the inner loop prints what goes in that row.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a pattern as a grid on graph paper. Each row has some spaces on the left and some stars after them. Once you know how many of each a row needs, the code almost writes itself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Pattern Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go pattern programs do not appear in real apps very often. However, they are one of the best ways to practise loop logic, because a single off-by-one mistake shows up right away in the shape.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fresher interviews:<\/strong> star pyramids and Floyd&#8217;s triangle are very common.<\/li>\n\n\n<li><strong>Loop control:<\/strong> you learn how the outer and inner loop counters relate.<\/li>\n\n\n<li><strong>Debugging skill:<\/strong> a wrong shape tells you exactly which count is off.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Pattern Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every pattern answers two questions for row <code>i<\/code>: how many spaces come first, and how many symbols come after them. Write those two counts as small formulas in <code>i<\/code>, and the loops follow.<\/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-pattern-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-1024x640.png\" alt=\"Go pattern programs diagram showing rows split into leading spaces and stars for a pyramid\" class=\"wp-image-726\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">For row i of an n-row pyramid, print n &#8211; i spaces, then 2i &#8211; 1 stars, then a new line.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below gives the formulas for the most common shapes, for row <code>i<\/code> from 1 to <code>n<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Pattern<\/th><th>Spaces in row i<\/th><th>Symbols in row i<\/th><\/tr><\/thead><tbody><tr><td>Right triangle<\/td><td>0<\/td><td>i<\/td><\/tr><tr><td>Inverted right triangle<\/td><td>0<\/td><td>n &#8211; i + 1<\/td><\/tr><tr><td>Right-aligned triangle<\/td><td>n &#8211; i<\/td><td>i<\/td><\/tr><tr><td>Pyramid<\/td><td>n &#8211; i<\/td><td>2i &#8211; 1<\/td><\/tr><tr><td>Inverted pyramid<\/td><td>i &#8211; 1<\/td><td>2(n &#8211; i) + 1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to Solve Any Go Pattern Program in Four Steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you write code, plan the shape on paper. This method works for almost all Go pattern programs, even ones you have never seen.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Draw the output<\/strong> for a small size, such as n = 4, and number the rows from 1.<\/li>\n\n\n<li><strong>Count each part of every row<\/strong>: leading spaces, symbols and any gap in the middle.<\/li>\n\n\n<li><strong>Turn the counts into formulas in i<\/strong>, for example 4 &#8211; i spaces and 2i &#8211; 1 stars.<\/li>\n\n\n<li><strong>Write one loop for the rows<\/strong> and print each part with <code>strings.Repeat<\/code> or an inner loop.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For example, take a right-aligned triangle with 4 rows. Row 1 has 3 spaces and 1 star, and row 4 has 0 spaces and 4 stars. So the spaces are n &#8211; i and the stars are i. With these two formulas, the program is just three lines long.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In short, the hard part of Go pattern programs is the counting, not the Go code. Once the formulas are right, the loops are always the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Star Go Pattern Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We start with star shapes, because they show the structure most clearly. The first one is the easiest of all, so it is a good warm-up.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Solid Square, the Easiest of the Go Pattern Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Every row of a square has the same number of stars. So the inner loop does not depend on the row at all.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    size := 4 \/\/ := creates a new variable and sets its value\n\n    \/\/ The outer loop prints one row each time it runs.\n    for i := 1; i &lt;= size; i++ {\n        \/\/ The inner loop prints the stars of the current row.\n        for j := 1; j &lt;= size; j++ {\n            fmt.Print(\"* \") \/\/ Print does not move to a new line\n        }\n        fmt.Println() \/\/ Println with nothing inside just ends the row\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * *\n* * * *\n* * * *\n* * * *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The outer loop runs 4 times, once for each row. Inside it, the inner loop prints 4 stars on the same line. Then <code>fmt.Println()<\/code> moves the cursor down, and the next row starts. Most Go pattern programs in this post follow this same two-loop shape.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Right Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Row <code>i<\/code> prints <code>i<\/code> stars. This version uses two loops, so you can see the structure.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    rows := 5\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ Row i gets exactly i stars.\n        for j := 1; j &lt;= i; j++ {\n            fmt.Print(\"* \")\n        }\n        fmt.Println() \/\/ end the row\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>*\n* *\n* * *\n* * * *\n* * * * *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The only change from the square is the inner loop limit. It stops at <code>i<\/code> instead of the full size, so the rows grow by one star each. <code>fmt.Println()<\/code> ends each row.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Inverted Right Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here we count the rows down instead of up. Also, <code>strings.Repeat<\/code> replaces the inner loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    rows := 5\n\n    \/\/ Start at 5 and count down to 1.\n    for i := rows; i &gt;= 1; i-- {\n        \/\/ strings.Repeat glues \"* \" together i times.\n        line := strings.Repeat(\"* \", i)\n        fmt.Println(line)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * * *\n* * * *\n* * *\n* *\n*<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strings.Repeat(\"* \", i)<\/code> builds the row in one step. Since <code>i<\/code> goes down from 5 to 1, each row is one star shorter. Most Go developers prefer this, because it is shorter and easier to read.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Right-Aligned Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now each row needs spaces before the stars, so the shape leans to the right.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    rows := 5\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ Step 1: the spaces push the stars to the right.\n        spaces := strings.Repeat(\" \", rows-i)\n        \/\/ Step 2: row i has i stars.\n        stars := strings.Repeat(\"*\", i)\n        \/\/ Step 3: join both parts with + and print them.\n        fmt.Println(spaces + stars)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>    *\n   **\n  ***\n ****\n*****<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Row 1 gets 4 spaces and 1 star. As <code>i<\/code> grows, the spaces shrink and the stars grow by one. The <code>+<\/code> sign joins the two strings into one line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Pyramid<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A pyramid needs <code>n - i<\/code> spaces and <code>2i - 1<\/code> stars in row <code>i<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    n := 5 \/\/ n is the number of rows, as in the diagram\n\n    for i := 1; i &lt;= n; i++ {\n        spaces := strings.Repeat(\" \", n-i)  \/\/ n - i spaces\n        stars := strings.Repeat(\"*\", 2*i-1) \/\/ 2i - 1 stars\n        fmt.Println(spaces + stars)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>    *\n   ***\n  *****\n *******\n*********<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Row 1 has 4 spaces and 1 star, while row 5 has no spaces and 9 stars. The odd star counts keep the pyramid centered.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Inverted Pyramid<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the pyramid turned upside down. The spaces now grow, and the stars shrink.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    rows := 5\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ Row 1 has no spaces, row 2 has one, and so on.\n        spaces := strings.Repeat(\" \", i-1)\n        \/\/ Row 1 has the most stars, and each row has 2 fewer.\n        stars := strings.Repeat(\"*\", 2*(rows-i)+1)\n        fmt.Println(spaces + stars)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>*********\n *******\n  *****\n   ***\n    *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In row 1, the formula <code>2*(5-1)+1<\/code> gives 9 stars. Each next row loses 2 stars and gains 1 space. So the shape narrows evenly from both sides.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Diamond<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A diamond is a pyramid followed by an inverted pyramid that skips its widest row.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\n\/\/ pyramidRow builds row number i of a pyramid that has the given number of rows.\nfunc pyramidRow(rows, i int) string {\n    spaces := strings.Repeat(\" \", rows-i)\n    stars := strings.Repeat(\"*\", 2*i-1)\n    return spaces + stars\n}\n\nfunc main() {\n    rows := 4\n\n    \/\/ Step 1: the top half, from row 1 down to the widest row.\n    for i := 1; i &lt;= rows; i++ {\n        fmt.Println(pyramidRow(rows, i))\n    }\n\n    \/\/ Step 2: the bottom half, going back up without the widest row.\n    for i := rows - 1; i &gt;= 1; i-- {\n        fmt.Println(pyramidRow(rows, i))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>   *\n  ***\n *****\n*******\n *****\n  ***\n   *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We moved the row logic into a function, so the two halves share it. The first loop prints rows 1 to 4. After that, the second loop prints rows 3, 2 and 1 again. This is a good habit for any repeated code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Hollow Square<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Inside a hollow square, only the edges get a star. We check whether the current cell sits on the border.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    size := 5\n\n    for i := 1; i &lt;= size; i++ {\n        for j := 1; j &lt;= size; j++ {\n            \/\/ || means \"or\": first row, last row, first column or last column.\n            onBorder := i == 1 || i == size || j == 1 || j == size\n\n            if onBorder {\n                fmt.Print(\"* \")\n            } else {\n                fmt.Print(\"  \") \/\/ two spaces keep the gap the same width\n            }\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>* * * * *\n*       *\n*       *\n*       *\n* * * * *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For every cell, <code>onBorder<\/code> is true or false. Border cells print a star, and inside cells print two spaces. That is why you need nested loops here, since each cell makes its own choice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Number and Letter Go Pattern Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The same loops can print numbers or letters instead of stars. These Go pattern programs are just as common in interviews.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Repeated Number Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This easy number pattern prints the row number again and again. It is a nice first step before the trickier number shapes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    rows := 5\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ Print the row number i, exactly i times.\n        for j := 1; j &lt;= i; j++ {\n            fmt.Print(i, \" \") \/\/ print the number and then a space\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n2 2\n3 3 3\n4 4 4 4\n5 5 5 5 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loops are the same as the right triangle in Program 2. The only change is that we print <code>i<\/code> instead of a star. So row 3 shows the number 3 three times.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Number Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now each row counts from 1 instead of repeating one number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    rows := 5\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ j counts 1, 2, 3 ... up to the row number.\n        for j := 1; j &lt;= i; j++ {\n            fmt.Print(j, \" \")\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1\n1 2\n1 2 3\n1 2 3 4\n1 2 3 4 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here we print <code>j<\/code>, not <code>i<\/code>. Each row starts again at 1, because <code>j<\/code> resets at the start of every row.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Floyd&#8217;s Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Floyd&#8217;s triangle, numbers keep counting across rows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    rows := 5\n    number := 1 \/\/ lives outside the loops, so it never goes back to 1\n\n    for i := 1; i &lt;= rows; i++ {\n        for j := 1; j &lt;= i; j++ {\n            fmt.Printf(\"%3d\", number) \/\/ %3d prints the number in 3 columns\n            number++                  \/\/ move to the next number\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  1\n  2  3\n  4  5  6\n  7  8  9 10\n 11 12 13 14 15<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>number<\/code> lives outside both loops, so it never resets. Each cell prints it and then adds one. <code>%3d<\/code> keeps the columns lined up when numbers reach two digits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Pascal&#8217;s Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Each number in Pascal&#8217;s triangle is the sum of the two numbers above it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    rows := 6\n    row := []int{1} \/\/ a slice (a growable list) that holds the current row\n\n    for i := 0; i &lt; rows; i++ {\n        \/\/ Step 1: print spaces so the triangle is centered.\n        fmt.Print(strings.Repeat(\" \", (rows-i-1)*2))\n\n        \/\/ Step 2: print every value in the current row.\n        \/\/ range gives the index and value; _ ignores the index.\n        for _, value := range row {\n            fmt.Printf(\"%4d\", value)\n        }\n        fmt.Println()\n\n        \/\/ Step 3: build the next row, which is one value longer.\n        nextRow := make([]int, len(row)+1) \/\/ make creates a slice filled with zeros\n        nextRow[0] = 1                     \/\/ first value is always 1\n        nextRow[len(row)] = 1              \/\/ last value is always 1\n        for j := 1; j &lt; len(row); j++ {\n            nextRow[j] = row[j-1] + row[j] \/\/ add the two values above\n        }\n        row = nextRow\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>             1\n           1   1\n         1   2   1\n       1   3   3   1\n     1   4   6   4   1\n   1   5  10  10   5   1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We build each new row from the previous one. The first and last values are always 1, and every middle value adds its two neighbours above. At the end of the loop, <code>nextRow<\/code> becomes the current row.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Alphabet Triangle<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Letters are runes, so we can add to them just like numbers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    rows := 5\n\n    for i := 0; i &lt; rows; i++ {\n        for j := 0; j &lt;= i; j++ {\n            \/\/ 'A' is a rune (a character code). 'A'+1 is 'B', and so on.\n            letter := 'A' + rune(j)\n            fmt.Printf(\"%c \", letter) \/\/ %c prints the rune as a letter\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>A\nA B\nA B C\nA B C D\nA B C D E<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>'A' + rune(j)<\/code> moves forward through the alphabet. <code>%c<\/code> prints the rune as a letter instead of a number. Both loops start at 0 here, so the first letter is <code>'A' + 0<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Number Pyramid<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Each row counts up to the row number and then back down.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    rows := 4\n\n    for i := 1; i &lt;= rows; i++ {\n        \/\/ Step 1: spaces on the left.\n        fmt.Print(strings.Repeat(\" \", rows-i))\n\n        \/\/ Step 2: count up from 1 to i.\n        for j := 1; j &lt;= i; j++ {\n            fmt.Print(j)\n        }\n\n        \/\/ Step 3: count back down from i-1 to 1.\n        for j := i - 1; j &gt;= 1; j-- {\n            fmt.Print(j)\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>   1\n  121\n 12321\n1234321<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each row counts up to <code>i<\/code> and back down. So it reads the same both ways, like a palindrome.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested Loops vs strings.Repeat in Go Pattern Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You have now seen both styles. The diagram and table below compare them.<\/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-pattern-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-1024x640.png\" alt=\"Go pattern programs comparison of nested loops and strings.Repeat\" class=\"wp-image-727\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Nested loops give cell-by-cell control, while strings.Repeat builds a full row in one call.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Nested loops<\/th><th>strings.Repeat<\/th><\/tr><\/thead><tbody><tr><td>Code length<\/td><td>Longer<\/td><td>Shorter<\/td><\/tr><tr><td>Control per cell<\/td><td>Full, can use if per cell<\/td><td>Same symbol for the whole run<\/td><\/tr><tr><td>Hollow shapes<\/td><td>Easy<\/td><td>Harder<\/td><\/tr><tr><td>Readability<\/td><td>Good for beginners<\/td><td>Very clear<\/td><\/tr><tr><td>Speed<\/td><td>Many small prints<\/td><td>Fewer, bigger prints<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use <code>strings.Repeat<\/code> for solid shapes, and nested loops when each cell needs its own decision, as in hollow shapes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Pattern Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Wrong space count:<\/strong> draw the first and last rows on paper and work out the formula from them.<\/li>\n\n\n<li><strong>Missing new line:<\/strong> forgetting <code>fmt.Println()<\/code> after a row puts everything on one line.<\/li>\n\n\n<li><strong>Resetting the wrong counter:<\/strong> in Floyd&#8217;s triangle, the number must live outside the loops.<\/li>\n\n\n<li><strong>Mixing Print and Println:<\/strong> <code>Println<\/code> adds spaces between values, which can break alignment.<\/li>\n\n\n<li><strong>Even rows for a diamond:<\/strong> the middle row must be the widest, so plan the halves carefully.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Pattern Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Write the formula first<\/strong>, as spaces and symbols for row <code>i<\/code>.<\/li>\n\n\n<li><strong>Use strings.Repeat<\/strong> for solid runs of the same character.<\/li>\n\n\n<li><strong>Move a row into a function<\/strong> when you print it more than once.<\/li>\n\n\n<li><strong>Use Printf widths<\/strong> like <code>%3d<\/code> when numbers have different lengths.<\/li>\n\n\n<li><strong>Test with n = 1 and n = 2<\/strong>, because small sizes show off-by-one errors quickly.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Pattern Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers often show you one of these Go pattern programs and ask for the output. Each program below is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Output Questions on Go Pattern Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. 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        for j := 1; j &lt;= 3; j++ {\n            fmt.Print(i * j) \/\/ row number times column number\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>123\n246\n369<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The inner loop multiplies the row number by 1, 2 and 3. So each row is a small times table.<\/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 (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    for i := 3; i &gt;= 1; i-- {\n        hashes := strings.Repeat(\"#\", i)   \/\/ i hash signs\n        dots := strings.Repeat(\".\", 3-i)   \/\/ fill the rest with dots\n        fmt.Println(hashes + dots)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>###\n##.\n#..<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Every row is 3 characters wide. As <code>i<\/code> counts down, there are fewer <code>#<\/code> signs and more dots to fill the gap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. 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;= 4; i++ {\n        for j := 1; j &lt;= 4; j++ {\n            if i == j {\n                fmt.Print(\"\\\\\") \/\/ \"\\\\\" is how you write one backslash\n            } else {\n                fmt.Print(\".\")\n            }\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\\...\n.\\..\n..\\.\n...\\<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A cell is on the main diagonal when the row number equals the column number. The string <code>\"\\\\\"<\/code> prints one backslash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. 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;= 4; i++ {\n        for j := 1; j &lt;= 4; j++ {\n            \/\/ % gives the remainder, so (i + j) % 2 is always 0 or 1.\n            fmt.Print((i + j) % 2)\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0101\n1010\n0101\n1010<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>(i + j) % 2<\/code> flips between 0 and 1 for each cell. This gives a chessboard pattern.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. 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 := 4; i &gt;= 1; i-- {\n        \/\/ Start at the row number and count down to 1.\n        for j := i; j &gt;= 1; j-- {\n            fmt.Print(j)\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4321\n321\n21\n1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both loops count down. The inner loop starts at the row number each time.<\/p>\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 := 0; i &lt; 3; i++ {\n        letter := 'a' + rune(i*2) \/\/ jump 2 letters each time\n        fmt.Printf(\"%c\\n\", letter) \/\/ \\n starts a new line\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a\nc\ne<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each step adds 2 to the rune, so it skips every other letter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Logic Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. How many stars does an n-row pyramid have in total?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Row i has 2i &#8211; 1 stars, and the sum of the first n odd numbers is n squared. So a 5-row pyramid has 25 stars.<\/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 (\n    \"fmt\"\n    \"strings\"\n)\n\nfunc main() {\n    total := 0\n\n    for i := 1; i &lt;= 5; i++ {\n        row := strings.Repeat(\"*\", 2*i-1)\n        total += len(row) \/\/ len gives the number of characters; += adds it to total\n    }\n    fmt.Println(total)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>25<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop builds each pyramid row and adds its length to <code>total<\/code>. The rows have 1, 3, 5, 7 and 9 stars, which add up to 25. This confirms the answer to Q7 with code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. How do you print a hollow triangle?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Print a star only when the cell is on an edge. For a right triangle, that means the first column, the last column of the row (<code>j == i<\/code>) or the last row (<code>i == n<\/code>). Print a space for every other cell.<\/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    size := 3\n\n    for i := 1; i &lt;= size; i++ {\n        for j := 1; j &lt;= size; j++ {\n            if j &lt;= i {\n                fmt.Print(\"*\")\n            } else {\n                fmt.Print(\"-\")\n            }\n        }\n        fmt.Println()\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>*--\n**-\n***<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Every row has 3 cells. Cells up to the row number get a star, and the rest get a dash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. How can you print a pattern faster for very large n?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build each row with <code>strings.Repeat<\/code> or a <code>strings.Builder<\/code>, and wrap output in <code>bufio.NewWriter(os.Stdout)<\/code>. Fewer, larger writes are much faster than thousands of single <code>fmt.Print<\/code> calls.<\/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    for i := 1; i &lt;= 3; i++ {\n        width := i * 2\n        \/\/ %*s takes the width from width, then pads \"*\" with spaces on the left.\n        line := fmt.Sprintf(\"%*s\", width, \"*\")\n        fmt.Println(line)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> *\n   *\n     *<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>%*s<\/code> reads the width from an argument. So the width is 2, 4 and 6, and the star is pushed further right each row.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The butterfly is one of the harder Go pattern programs. Print it for n = 4: two right triangles that face each other, with spaces in the middle. Hint: row <code>i<\/code> needs <code>i<\/code> stars, then <code>2*(n-i)<\/code> spaces, then <code>i<\/code> stars again, and the bottom half mirrors the top.<\/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:\/\/pkg.go.dev\/strings#Repeat\">strings package: Repeat<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/fmt\">fmt package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/tour\/flowcontrol\/1\">A Tour of Go: For<\/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 pattern programs use an outer loop for rows and an inner loop or <code>strings.Repeat<\/code> for each row.<\/li>\n\n\n<li>Work out two formulas for row <code>i<\/code>: the number of spaces and the number of symbols.<\/li>\n\n\n<li>A pyramid row has <code>n - i<\/code> spaces and <code>2i - 1<\/code> stars.<\/li>\n\n\n<li>Use nested loops with an <code>if<\/code> for hollow shapes and checkerboards.<\/li>\n\n\n<li>Use <code>%3d<\/code> style widths when number patterns have different digit lengths.<\/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, we finish Level 2 with menus and calculators. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-switch-calculator-programs\/\">Go switch programs with a calculator example<\/a>. To revise strings before that, see our <a href=\"https:\/\/smitabharat.com\/blog\/go-strings-examples\/\">Go strings guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go pattern programs print shapes such as triangles, pyramids and diamonds using stars, numbers or letters. They look simple, but they test exactly how&hellip;<\/p>\n","protected":false},"author":1,"featured_media":728,"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,111,104],"swapz_series":[],"class_list":["post-741","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-pattern-programs","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 Pattern Programs: Star, Number and Pyramid<\/title>\n<meta name=\"description\" content=\"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern 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-pattern-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Pattern Programs: Star, Number and Pyramid\" \/>\n<meta property=\"og:description\" content=\"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern interview questions with answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T05: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-pattern-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=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Pattern Programs: Star, Number and Pyramid Patterns\",\"datePublished\":\"2026-10-05T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/\"},\"wordCount\":1977,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pattern-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Pattern Programs\",\"Go Programs\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/\",\"name\":\"Go Pattern Programs: Star, Number and Pyramid\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pattern-programs-featured.png\",\"datePublished\":\"2026-10-05T05:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:40+00:00\",\"description\":\"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern interview questions with answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pattern-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-pattern-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Pattern Programs featured image: star pyramid printed in a terminal\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-pattern-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Pattern Programs: Star, Number and Pyramid Patterns\"}]},{\"@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 Pattern Programs: Star, Number and Pyramid","description":"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern 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-pattern-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Pattern Programs: Star, Number and Pyramid","og_description":"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern interview questions with answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-05T05: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-pattern-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Pattern Programs: Star, Number and Pyramid Patterns","datePublished":"2026-10-05T05:30:00+00:00","dateModified":"2026-11-28T19:59:40+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/"},"wordCount":1977,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Pattern Programs","Go Programs"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/","name":"Go Pattern Programs: Star, Number and Pyramid","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-featured.png","datePublished":"2026-10-05T05:30:00+00:00","dateModified":"2026-11-28T19:59:40+00:00","description":"Go pattern programs with output: star triangles, pyramids, diamond, Floyd and Pascal triangles, plus pattern interview questions with answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-pattern-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-pattern-programs-featured.png","width":2400,"height":1260,"caption":"Go Pattern Programs featured image: star pyramid printed in a terminal"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Pattern Programs: Star, Number and Pyramid Patterns"}]},{"@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\/741","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=741"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/741\/revisions"}],"predecessor-version":[{"id":875,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/741\/revisions\/875"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/728"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=741"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}