[{"data":1,"prerenderedAt":251},["ShallowReactive",2],{"tag-labels":3,"site-header":4,"article-go-program-structure-and-variables-en":72},{},{"featuredPost":5,"navigations":29},{"id":6,"title":7,"title_id":8,"slug":9,"excerpt":10,"excerpt_id":11,"has_translation":12,"published_at":13,"reading_time":14,"hidden_from_listing":15,"tags":16,"thumbnail_image":21,"og_image":22,"series":23,"authors":28},110,"When You Pick a Framework Just to Look Different","Ketika Pilih Framework Cuma Biar Kelihatan Beda","ketika-pilih-framework-cuma-biar-kelihatan-beda","The last time you chose a new framework or library, was it because your problem needed that tool, or because it sounded cool and few people around you were using it? That question is uncomfortable. Technology decisions are often made for reasons that never appear in any technical document.","Terakhir kali kamu milih framework atau library baru, itu karena masalahmu butuh alat itu, atau karena alatnya kedengaran keren dan belum banyak yang pakai? Pertanyaan ini nggak enak dijawab. Soalnya keputusan teknologi sering diambil dengan alasan yang nggak pernah ditulis di dokumen teknis mana pun.",true,"2026-10-06T15:25:21.000Z",5,false,[17,18,19,20],"karier","framework","opini","pengalaman",null,"\u002Fog\u002Fketika-pilih-framework-cuma-biar-kelihatan-beda.png",{"id":24,"title":25,"title_id":26,"slug":27},9,"Articles","Artikel","all",[],[30,46,67],{"collection":31,"item":32},"series",{"__typename":31,"title":25,"title_id":26,"slug":27,"children_series":33},[34,38,42],{"title":35,"title_id":36,"slug":37},"Artificial Intelligence","Kecerdasan Artifisial","kecerdasan-artifisial",{"title":39,"title_id":40,"slug":41},"Programming Fundamentals","Konsep Dasar Pemrograman","konsep-dasar-pemrograman",{"title":43,"title_id":44,"slug":45},"Algorithms and Data Structures","Algoritma dan Struktur Data","algoritma-struktur-data",{"collection":31,"item":47},{"__typename":31,"title":48,"title_id":48,"slug":49,"children_series":50},"Tutorial","tutorial",[51,55,59,63],{"title":52,"title_id":53,"slug":54},"Learning Python","Belajar Python","belajar-python",{"title":56,"title_id":57,"slug":58},"Learning Go","Belajar Golang","belajar-golang",{"title":60,"title_id":61,"slug":62},"Learning Java","Belajar Java","belajar-java",{"title":64,"title_id":65,"slug":66},"Learning Pascal","Belajar Pascal","belajar-pascal",{"collection":31,"item":68},{"__typename":31,"title":69,"title_id":69,"slug":70,"children_series":71},"Lab","lab",[],{"article":73,"renderedBody":136,"renderedTakeaway":137,"latestArticles":138,"toc":234},{"id":74,"title":75,"title_id":21,"slug":76,"excerpt":77,"excerpt_id":21,"has_translation":15,"published_at":78,"reading_time":79,"hidden_from_listing":15,"tags":80,"thumbnail_image":21,"og_image":84,"series":85,"authors":128,"seoTitle":21,"seoDescription":21,"body_locale":131,"available_locales":132,"body":134,"takeway":135,"prerequisite":21},148,"Go Variables: the Mean That Printed 0.0","go-program-structure-and-variables","Six scores arrive, all six are added up, and Go prints a mean of 0.0. A second `total := 0` inside the `if` block is the whole bug, and the compiler that refuses unused variables has nothing to say about it.","2026-11-11T01:00:00.000Z",6,[81,82,83],"go","dasar","variabel","\u002Fog\u002Fgo-program-structure-and-variables.png",{"id":86,"title":56,"title_id":57,"slug":58,"description":87,"description_id":21,"articles":88,"children_series":118,"parent_series":119},11,"Go from zero: the shape of the language, why it looks the way it does, and what it's good at.",[89,113],{"id":90,"title":91,"title_id":92,"slug":93,"excerpt":94,"excerpt_id":95,"has_translation":12,"published_at":96,"reading_time":97,"hidden_from_listing":15,"tags":98,"thumbnail_image":21,"og_image":104,"series":105,"authors":106},30,"Meet Go: Why So Many Backend Teams Reach for It","Berkenalan dengan Bahasa Go: Kenapa Banyak Dipakai untuk Backend Modern?","berkenalan-dengan-bahasa-go-untuk-backend-modern","How did a young language end up inside Docker and Kubernetes? Meet Goroutines, Channels, and the reason Go is so stingy with memory.","Kok bisa sih Go yang masih muda ini jadi bahasa andalan Docker sampai Kubernetes? Yuk, kita kenalan sama Goroutine, Channel, dan alasan dia hemat memori luar biasa!","2026-08-17T04:26:10.344Z",4,[99,81,100,101,102,103],"golang","backend","concurrency","goroutine","system-design","\u002Fog\u002Fberkenalan-dengan-bahasa-go-untuk-backend-modern.png",{"id":86,"title":56,"title_id":57,"slug":58},[107],{"authors_id":108},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},1,"Daffa Izzuddin","izzudd","Writer",{"id":74,"title":75,"title_id":21,"slug":76,"excerpt":77,"excerpt_id":21,"has_translation":15,"published_at":78,"reading_time":79,"hidden_from_listing":15,"tags":80,"thumbnail_image":21,"og_image":84,"series":114,"authors":115},{"id":86,"title":56,"title_id":57,"slug":58},[116],{"authors_id":117},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},[],{"id":109,"title":48,"title_id":48,"slug":49,"parent_series":21,"children_series":120},[121,123,124,126],{"id":122,"title":52,"title_id":53,"slug":54,"cover_image":21},10,{"id":86,"title":56,"title_id":57,"slug":58,"cover_image":21},{"id":125,"title":60,"title_id":61,"slug":62,"cover_image":21},13,{"id":127,"title":64,"title_id":65,"slug":66,"cover_image":21},14,[129],{"authors_id":130},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},"en",[131,133],"id","\nA Go program reads six test scores, adds them up, and prints a mean of 0.0. The line above it says `count: 6`, so every number arrived. The compiler accepted the file without a word, and `go vet`, the standard tool for spotting suspicious code, printed nothing at all. Save the scores in `scores.txt`, one per line: 72, 85, 91, 64, 78, 67. The correct mean is 76.2, which is 457 over 6.\n\n```go\n\u002F\u002F scores.go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tscanner := bufio.NewScanner(os.Stdin)\n\tscores := []int{}\n\tfor scanner.Scan() {\n\t\tn, err := strconv.Atoi(scanner.Text())\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tscores = append(scores, n)\n\t}\n\n\ttotal := 0\n\tif len(scores) > 0 {\n\t\ttotal := 0\n\t\tfor _, s := range scores {\n\t\t\ttotal += s\n\t\t}\n\t}\n\n\tfmt.Printf(\"count: %d\\n\", len(scores))\n\tfmt.Printf(\"mean: %.1f\\n\", float64(total)\u002Ffloat64(len(scores)))\n}\n```\n\n```plain\n$ go run scores.go \u003C scores.txt\ncount: 6\nmean: 0.0\n```\n\nThe cause is the second `total := 0`. It declares a new variable that lives only inside the `if` block, so the loop fills that one and the outer `total` stays 0.\n\n## The three parts of a Go file\n\nEvery program here starts with `package main`, which names the package the file belongs to. `main` is the package `go run` starts from. Next comes `import`, which lists the packages the file uses. In `scores.go`, `fmt` prints text and `strconv` turns text into numbers.\n\nThen comes `func main`, the function that runs first. A file without it fails to build with `function main is undeclared in the main package`.\n\n## Declaring variables\n\nSave this as `main.go` and run it. The first five lines of `main` use `var`, which declares a name and a type without a value.\n\n```go\n\u002F\u002F main.go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tvar total int\n\tvar name string\n\tvar ready bool\n\tvar ratio float64\n\tvar list []string\n\n\tfmt.Printf(\"int=%d string=%q bool=%v float=%v slice=%v\\n\", total, name, ready, ratio, list == nil)\n\n\tscores := []int{72, 85, 91}\n\tsum := 0\n\tfor _, s := range scores {\n\t\tsum += s\n\t}\n\tfmt.Printf(\"sum=%d mean=%.1f\\n\", sum, float64(sum)\u002Ffloat64(len(scores)))\n\n\tlimit := 5\n\tif limit > 0 {\n\t\tlimit := 10\n\t\tfmt.Println(\"inside the block:\", limit)\n\t}\n\tfmt.Println(\"after the block:\", limit)\n}\n```\n\n```plain\n$ go run main.go\nint=0 string=\"\" bool=false float=0 slice=true\nsum=248 mean=82.7\ninside the block: 10\nafter the block: 5\n```\n\nGo fills each `var` with the zero value of its type: `0` for an integer, `\"\"` for a string (the `%q` verb prints the quotes), `false` for a bool, and `0` for a float. A slice is a list that can grow. One declared with `var` is nil and has length 0, which is why `list == nil` prints `slice=true`.\n\nThe `:=` form declares and assigns in one statement, and the type comes from the value on the right. So `scores := []int{72, 85, 91}` is a slice of three ints. Their sum is 248, and 248 divided by 3 is 82.666…, which `%.1f` prints as 82.7.\n\n## When := makes a second variable\n\nA block is the code between a pair of braces. The last four lines of `main.go` declare `limit := 5` and then declare `limit := 10` inside an `if` block. Inside a block, `:=` with a name that already exists outside creates a new variable that ends at the closing brace. The output shows both: 10 inside, 5 after. Go calls this shadowing.\n\nThat is the bug in `scores.go`. The inner `total` is the one the loop adds to, and the closing brace throws it away. The `Printf` at the bottom reads the outer `total`, which is still 0.\n\n## The one rule the compiler enforces\n\nGo refuses to build a program with an unused variable. Save this as `unused.go`. It prints one line and declares a `bonus` that nothing reads:\n\n```go\n\u002F\u002F unused.go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"three scores\")\n\tbonus := 5\n}\n```\n\n```plain\n$ go run unused.go\n# command-line-arguments\n.\u002Funused.go:8:2: declared and not used: bonus\n```\n\nThe error names the file, the line, and the column, so `.\u002Funused.go:8:2` points at line 8, column 2 of `unused.go`. The program exits with status 1. The rule is about declarations, not values: the compiler checks that every declared name is mentioned somewhere. A name used inside a block counts as used. The inner `total` is used by `total += s`, so `scores.go` compiles.\n\n## Check the fix with a second program\n\nYou spotted the wrong mean because you already knew the answer. A checker makes that comparison mechanical. Save this as `check_main.go`. It reads another program's output from standard input and compares it with two expected lines.\n\n```go\n\u002F\u002F check_main.go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strings\"\n)\n\nfunc main() {\n\twant := []string{\"count: 6\", \"mean: 76.2\"}\n\tgot := []string{}\n\tscanner := bufio.NewScanner(os.Stdin)\n\tfor scanner.Scan() {\n\t\tline := strings.TrimRight(scanner.Text(), \"\\r\")\n\t\tif line != \"\" {\n\t\t\tgot = append(got, line)\n\t\t}\n\t}\n\n\tpassed, failed := 0, 0\n\tfor i := range want {\n\t\tif i \u003C len(got) && got[i] == want[i] {\n\t\t\tfmt.Printf(\"PASS  line %d: %s\\n\", i+1, want[i])\n\t\t\tpassed++\n\t\t\tcontinue\n\t\t}\n\t\tif i \u003C len(got) {\n\t\t\tfmt.Printf(\"FAIL  line %d: expected %q, got %q\\n\", i+1, want[i], got[i])\n\t\t} else {\n\t\t\tfmt.Printf(\"FAIL  line %d: expected %q, no such line\\n\", i+1, want[i])\n\t\t}\n\t\tfailed++\n\t}\n\n\tfmt.Printf(\"\\n%d of %d checks passed\\n\", passed, len(want))\n\tif failed > 0 {\n\t\tos.Exit(1)\n\t}\n}\n```\n\nThe pipe (`|`) sends the output of `scores.go` into the checker's input. Run it against the broken version:\n\n```plain\n$ go run scores.go \u003C scores.txt | go run check_main.go\nPASS  line 1: count: 6\nFAIL  line 2: expected \"mean: 76.2\", got \"mean: 0.0\"\n\n1 of 2 checks passed\nexit status 1\n```\n\nThe checker exited with status 1, and `go run` printed that as the last line. Now delete the second `total := 0` from `scores.go`, so the loop adds to the `total` declared above the block:\n\n```go\n\u002F\u002F scores.go\npackage main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n)\n\nfunc main() {\n\tscanner := bufio.NewScanner(os.Stdin)\n\tscores := []int{}\n\tfor scanner.Scan() {\n\t\tn, err := strconv.Atoi(scanner.Text())\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tscores = append(scores, n)\n\t}\n\n\ttotal := 0\n\tif len(scores) > 0 {\n\t\tfor _, s := range scores {\n\t\t\ttotal += s\n\t\t}\n\t}\n\n\tfmt.Printf(\"count: %d\\n\", len(scores))\n\tfmt.Printf(\"mean: %.1f\\n\", float64(total)\u002Ffloat64(len(scores)))\n}\n```\n\n```plain\n$ go run scores.go \u003C scores.txt | go run check_main.go\nPASS  line 1: count: 6\nPASS  line 2: mean: 76.2\n\n2 of 2 checks passed\n```\n\nThe checker now exits with status 0, so a script can gate on it.\n\nI declare a variable in the innermost block that contains every line that reads or writes it. In a deeper block I change it with `=` or `+=`, because `:=` there starts a new variable that ends at the next closing brace.\n","- `package main`, `import`, and `func main` are the three parts of a runnable Go file, and a file without `func main` fails with `function main is undeclared in the main package`.\n- `var name type` declares without a value, and Go fills the variable with that type's zero value: `0`, `\"\"`, `false`, `0`, or a nil slice.\n- `:=` declares and assigns in one statement and takes the type from the right-hand side.\n- A `:=` inside a block declares a new variable that ends at the closing brace, even when the same name exists outside, which is what shadowing means.\n- Go refuses to build a program with a declared and unused variable (`declared and not used: bonus`), but a shadowed variable counts as used, so the compiler stays quiet.\n- `go vet` printed nothing at all on the shadowed program, so the wrong mean survived every automatic check.","\u003Cp>A Go program reads six test scores, adds them up, and prints a mean of 0.0. The line above it says \u003Ccode>count: 6\u003C\u002Fcode>, so every number arrived. The compiler accepted the file without a word, and \u003Ccode>go vet\u003C\u002Fcode>, the standard tool for spotting suspicious code, printed nothing at all. Save the scores in \u003Ccode>scores.txt\u003C\u002Fcode>, one per line: 72, 85, 91, 64, 78, 67. The correct mean is 76.2, which is 457 over 6.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">GO\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%2F%2F%20scores.go%0Apackage%20main%0A%0Aimport%20(%0A%09%22bufio%22%0A%09%22fmt%22%0A%09%22os%22%0A%09%22strconv%22%0A)%0A%0Afunc%20main()%20%7B%0A%09scanner%20%3A%3D%20bufio.NewScanner(os.Stdin)%0A%09scores%20%3A%3D%20%5B%5Dint%7B%7D%0A%09for%20scanner.Scan()%20%7B%0A%09%09n%2C%20err%20%3A%3D%20strconv.Atoi(scanner.Text())%0A%09%09if%20err%20!%3D%20nil%20%7B%0A%09%09%09continue%0A%09%09%7D%0A%09%09scores%20%3D%20append(scores%2C%20n)%0A%09%7D%0A%0A%09total%20%3A%3D%200%0A%09if%20len(scores)%20%3E%200%20%7B%0A%09%09total%20%3A%3D%200%0A%09%09for%20_%2C%20s%20%3A%3D%20range%20scores%20%7B%0A%09%09%09total%20%2B%3D%20s%0A%09%09%7D%0A%09%7D%0A%0A%09fmt.Printf(%22count%3A%20%25d%5Cn%22%2C%20len(scores))%0A%09fmt.Printf(%22mean%3A%20%25.1f%5Cn%22%2C%20float64(total)%2Ffloat64(len(scores)))%0A%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\">\u002F\u002F scores.go\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">package\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> (\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">bufio\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">fmt\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">os\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">strconv\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">func\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscanner \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> bufio.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">NewScanner\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(os.Stdin)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscores \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">int\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">{}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Scan\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tn, err \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> strconv.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Atoi\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Text\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">())\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> err \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">!=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> nil\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\t\tcontinue\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tscores \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> append\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores, n)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\ttotal \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tif\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">>\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\ttotal \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> _, s \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> range\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scores {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\ttotal \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> s\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"count: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"mean: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%.1f\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">float64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(total)\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">\u002Ffloat64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores)))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003Cdiv class=\"code-block-wrapper code-output my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden text-[#e1e4e8] transition-all\" data-output-block>\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"code-output-mark\" aria-hidden=\"true\">&gt;_\u003C\u002Fspan>\n      \u003Cspan class=\"ml-1 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">Output\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20go%20run%20scores.go%20%3C%20scores.txt%0Acount%3A%206%0Amean%3A%200.0\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>\u003Cspan class=\"code-output-cmd\">$ go run scores.go &lt; scores.txt\u003C\u002Fspan>\ncount: 6\nmean: 0.0\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The cause is the second \u003Ccode>total := 0\u003C\u002Fcode>. It declares a new variable that lives only inside the \u003Ccode>if\u003C\u002Fcode> block, so the loop fills that one and the outer \u003Ccode>total\u003C\u002Fcode> stays 0.\u003C\u002Fp>\n\u003Ch2 id=\"the-three-parts-of-a-go-file\">The three parts of a Go file\u003C\u002Fh2>\n\u003Cp>Every program here starts with \u003Ccode>package main\u003C\u002Fcode>, which names the package the file belongs to. \u003Ccode>main\u003C\u002Fcode> is the package \u003Ccode>go run\u003C\u002Fcode> starts from. Next comes \u003Ccode>import\u003C\u002Fcode>, which lists the packages the file uses. In \u003Ccode>scores.go\u003C\u002Fcode>, \u003Ccode>fmt\u003C\u002Fcode> prints text and \u003Ccode>strconv\u003C\u002Fcode> turns text into numbers.\u003C\u002Fp>\n\u003Cp>Then comes \u003Ccode>func main\u003C\u002Fcode>, the function that runs first. A file without it fails to build with \u003Ccode>function main is undeclared in the main package\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Ch2 id=\"declaring-variables\">Declaring variables\u003C\u002Fh2>\n\u003Cp>Save this as \u003Ccode>main.go\u003C\u002Fcode> and run it. The first five lines of \u003Ccode>main\u003C\u002Fcode> use \u003Ccode>var\u003C\u002Fcode>, which declares a name and a type without a value.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">GO\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%2F%2F%20main.go%0Apackage%20main%0A%0Aimport%20%22fmt%22%0A%0Afunc%20main()%20%7B%0A%09var%20total%20int%0A%09var%20name%20string%0A%09var%20ready%20bool%0A%09var%20ratio%20float64%0A%09var%20list%20%5B%5Dstring%0A%0A%09fmt.Printf(%22int%3D%25d%20string%3D%25q%20bool%3D%25v%20float%3D%25v%20slice%3D%25v%5Cn%22%2C%20total%2C%20name%2C%20ready%2C%20ratio%2C%20list%20%3D%3D%20nil)%0A%0A%09scores%20%3A%3D%20%5B%5Dint%7B72%2C%2085%2C%2091%7D%0A%09sum%20%3A%3D%200%0A%09for%20_%2C%20s%20%3A%3D%20range%20scores%20%7B%0A%09%09sum%20%2B%3D%20s%0A%09%7D%0A%09fmt.Printf(%22sum%3D%25d%20mean%3D%25.1f%5Cn%22%2C%20sum%2C%20float64(sum)%2Ffloat64(len(scores)))%0A%0A%09limit%20%3A%3D%205%0A%09if%20limit%20%3E%200%20%7B%0A%09%09limit%20%3A%3D%2010%0A%09%09fmt.Println(%22inside%20the%20block%3A%22%2C%20limit)%0A%09%7D%0A%09fmt.Println(%22after%20the%20block%3A%22%2C%20limit)%0A%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\">\u002F\u002F main.go\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">package\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">fmt\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">func\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tvar\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> total \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">int\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tvar\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> name \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">string\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tvar\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> ready \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">bool\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tvar\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> ratio \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">float64\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tvar\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> list []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">string\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"int=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> string=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%q\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> bool=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%v\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> float=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%v\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> slice=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%v\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, total, name, ready, ratio, list \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">==\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> nil\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscores \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">int\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">{\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">72\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">85\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">91\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tsum \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> _, s \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> range\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scores {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tsum \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> s\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"sum=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> mean=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%.1f\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, sum, \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">float64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(sum)\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">\u002Ffloat64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores)))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tlimit \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 5\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> limit \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">>\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tlimit \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 10\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Println\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"inside the block:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, limit)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Println\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"after the block:\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, limit)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003Cdiv class=\"code-block-wrapper code-output my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden text-[#e1e4e8] transition-all\" data-output-block>\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"code-output-mark\" aria-hidden=\"true\">&gt;_\u003C\u002Fspan>\n      \u003Cspan class=\"ml-1 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">Output\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20go%20run%20main.go%0Aint%3D0%20string%3D%22%22%20bool%3Dfalse%20float%3D0%20slice%3Dtrue%0Asum%3D248%20mean%3D82.7%0Ainside%20the%20block%3A%2010%0Aafter%20the%20block%3A%205\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>\u003Cspan class=\"code-output-cmd\">$ go run main.go\u003C\u002Fspan>\nint=0 string=\"\" bool=false float=0 slice=true\nsum=248 mean=82.7\ninside the block: 10\nafter the block: 5\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>Go fills each \u003Ccode>var\u003C\u002Fcode> with the zero value of its type: \u003Ccode>0\u003C\u002Fcode> for an integer, \u003Ccode>&quot;&quot;\u003C\u002Fcode> for a string (the \u003Ccode>%q\u003C\u002Fcode> verb prints the quotes), \u003Ccode>false\u003C\u002Fcode> for a bool, and \u003Ccode>0\u003C\u002Fcode> for a float. A slice is a list that can grow. One declared with \u003Ccode>var\u003C\u002Fcode> is nil and has length 0, which is why \u003Ccode>list == nil\u003C\u002Fcode> prints \u003Ccode>slice=true\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Cp>The \u003Ccode>:=\u003C\u002Fcode> form declares and assigns in one statement, and the type comes from the value on the right. So \u003Ccode>scores := []int{72, 85, 91}\u003C\u002Fcode> is a slice of three ints. Their sum is 248, and 248 divided by 3 is 82.666…, which \u003Ccode>%.1f\u003C\u002Fcode> prints as 82.7.\u003C\u002Fp>\n\u003Ch2 id=\"when-makes-a-second-variable\">When := makes a second variable\u003C\u002Fh2>\n\u003Cp>A block is the code between a pair of braces. The last four lines of \u003Ccode>main.go\u003C\u002Fcode> declare \u003Ccode>limit := 5\u003C\u002Fcode> and then declare \u003Ccode>limit := 10\u003C\u002Fcode> inside an \u003Ccode>if\u003C\u002Fcode> block. Inside a block, \u003Ccode>:=\u003C\u002Fcode> with a name that already exists outside creates a new variable that ends at the closing brace. The output shows both: 10 inside, 5 after. Go calls this shadowing.\u003C\u002Fp>\n\u003Cp>That is the bug in \u003Ccode>scores.go\u003C\u002Fcode>. The inner \u003Ccode>total\u003C\u002Fcode> is the one the loop adds to, and the closing brace throws it away. The \u003Ccode>Printf\u003C\u002Fcode> at the bottom reads the outer \u003Ccode>total\u003C\u002Fcode>, which is still 0.\u003C\u002Fp>\n\u003Ch2 id=\"the-one-rule-the-compiler-enforces\">The one rule the compiler enforces\u003C\u002Fh2>\n\u003Cp>Go refuses to build a program with an unused variable. Save this as \u003Ccode>unused.go\u003C\u002Fcode>. It prints one line and declares a \u003Ccode>bonus\u003C\u002Fcode> that nothing reads:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">GO\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%2F%2F%20unused.go%0Apackage%20main%0A%0Aimport%20%22fmt%22%0A%0Afunc%20main()%20%7B%0A%09fmt.Println(%22three%20scores%22)%0A%09bonus%20%3A%3D%205%0A%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\">\u002F\u002F unused.go\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">package\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">fmt\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">func\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Println\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"three scores\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tbonus \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 5\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003Cdiv class=\"code-block-wrapper code-output my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden text-[#e1e4e8] transition-all\" data-output-block>\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"code-output-mark\" aria-hidden=\"true\">&gt;_\u003C\u002Fspan>\n      \u003Cspan class=\"ml-1 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">Output\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20go%20run%20unused.go%0A%23%20command-line-arguments%0A.%2Funused.go%3A8%3A2%3A%20declared%20and%20not%20used%3A%20bonus\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>\u003Cspan class=\"code-output-cmd\">$ go run unused.go\u003C\u002Fspan>\n# command-line-arguments\n.\u002Funused.go:8:2: declared and not used: bonus\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The error names the file, the line, and the column, so \u003Ccode>.\u002Funused.go:8:2\u003C\u002Fcode> points at line 8, column 2 of \u003Ccode>unused.go\u003C\u002Fcode>. The program exits with status 1. The rule is about declarations, not values: the compiler checks that every declared name is mentioned somewhere. A name used inside a block counts as used. The inner \u003Ccode>total\u003C\u002Fcode> is used by \u003Ccode>total += s\u003C\u002Fcode>, so \u003Ccode>scores.go\u003C\u002Fcode> compiles.\u003C\u002Fp>\n\u003Ch2 id=\"check-the-fix-with-a-second-program\">Check the fix with a second program\u003C\u002Fh2>\n\u003Cp>You spotted the wrong mean because you already knew the answer. A checker makes that comparison mechanical. Save this as \u003Ccode>check_main.go\u003C\u002Fcode>. It reads another program&#39;s output from standard input and compares it with two expected lines.\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">GO\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%2F%2F%20check_main.go%0Apackage%20main%0A%0Aimport%20(%0A%09%22bufio%22%0A%09%22fmt%22%0A%09%22os%22%0A%09%22strings%22%0A)%0A%0Afunc%20main()%20%7B%0A%09want%20%3A%3D%20%5B%5Dstring%7B%22count%3A%206%22%2C%20%22mean%3A%2076.2%22%7D%0A%09got%20%3A%3D%20%5B%5Dstring%7B%7D%0A%09scanner%20%3A%3D%20bufio.NewScanner(os.Stdin)%0A%09for%20scanner.Scan()%20%7B%0A%09%09line%20%3A%3D%20strings.TrimRight(scanner.Text()%2C%20%22%5Cr%22)%0A%09%09if%20line%20!%3D%20%22%22%20%7B%0A%09%09%09got%20%3D%20append(got%2C%20line)%0A%09%09%7D%0A%09%7D%0A%0A%09passed%2C%20failed%20%3A%3D%200%2C%200%0A%09for%20i%20%3A%3D%20range%20want%20%7B%0A%09%09if%20i%20%3C%20len(got)%20%26%26%20got%5Bi%5D%20%3D%3D%20want%5Bi%5D%20%7B%0A%09%09%09fmt.Printf(%22PASS%20%20line%20%25d%3A%20%25s%5Cn%22%2C%20i%2B1%2C%20want%5Bi%5D)%0A%09%09%09passed%2B%2B%0A%09%09%09continue%0A%09%09%7D%0A%09%09if%20i%20%3C%20len(got)%20%7B%0A%09%09%09fmt.Printf(%22FAIL%20%20line%20%25d%3A%20expected%20%25q%2C%20got%20%25q%5Cn%22%2C%20i%2B1%2C%20want%5Bi%5D%2C%20got%5Bi%5D)%0A%09%09%7D%20else%20%7B%0A%09%09%09fmt.Printf(%22FAIL%20%20line%20%25d%3A%20expected%20%25q%2C%20no%20such%20line%5Cn%22%2C%20i%2B1%2C%20want%5Bi%5D)%0A%09%09%7D%0A%09%09failed%2B%2B%0A%09%7D%0A%0A%09fmt.Printf(%22%5Cn%25d%20of%20%25d%20checks%20passed%5Cn%22%2C%20passed%2C%20len(want))%0A%09if%20failed%20%3E%200%20%7B%0A%09%09os.Exit(1)%0A%09%7D%0A%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\">\u002F\u002F check_main.go\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">package\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> (\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">bufio\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">fmt\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">os\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">strings\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">func\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\twant \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">string\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">{\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"count: 6\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"mean: 76.2\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tgot \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">string\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">{}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscanner \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> bufio.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">NewScanner\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(os.Stdin)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Scan\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tline \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> strings.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">TrimRight\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Text\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(), \u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\r\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> line \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">!=\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> \"\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\tgot \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> append\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(got, line)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tpassed, failed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> i \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> range\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> want {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> i \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(got) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">&#x26;&#x26;\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> got[i] \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">==\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> want[i] {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"PASS  line \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%s\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, i\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, want[i])\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\tpassed\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">++\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\t\tcontinue\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> i \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">&#x3C;\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(got) {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"FAIL  line \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">: expected \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%q\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">, got \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%q\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, i\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, want[i], got[i])\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t} \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">else\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"FAIL  line \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">: expected \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%q\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">, no such line\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, i\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, want[i])\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tfailed\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">++\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> of \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\"> checks passed\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, passed, \u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(want))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> failed \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">>\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tos.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Exit\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">1\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The pipe (\u003Ccode>|\u003C\u002Fcode>) sends the output of \u003Ccode>scores.go\u003C\u002Fcode> into the checker&#39;s input. Run it against the broken version:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper code-output my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden text-[#e1e4e8] transition-all\" data-output-block>\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"code-output-mark\" aria-hidden=\"true\">&gt;_\u003C\u002Fspan>\n      \u003Cspan class=\"ml-1 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">Output\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20go%20run%20scores.go%20%3C%20scores.txt%20%7C%20go%20run%20check_main.go%0APASS%20%20line%201%3A%20count%3A%206%0AFAIL%20%20line%202%3A%20expected%20%22mean%3A%2076.2%22%2C%20got%20%22mean%3A%200.0%22%0A%0A1%20of%202%20checks%20passed%0Aexit%20status%201\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>\u003Cspan class=\"code-output-cmd\">$ go run scores.go &lt; scores.txt | go run check_main.go\u003C\u002Fspan>\nPASS  line 1: count: 6\nFAIL  line 2: expected \"mean: 76.2\", got \"mean: 0.0\"\n\n1 of 2 checks passed\nexit status 1\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The checker exited with status 1, and \u003Ccode>go run\u003C\u002Fcode> printed that as the last line. Now delete the second \u003Ccode>total := 0\u003C\u002Fcode> from \u003Ccode>scores.go\u003C\u002Fcode>, so the loop adds to the \u003Ccode>total\u003C\u002Fcode> declared above the block:\u003C\u002Fp>\n\n\u003Cdiv class=\"code-block-wrapper my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden bg-[#24292e] text-[#e1e4e8] transition-all\">\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ff5f56] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#ffbd2e] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"w-3 h-3 rounded-full bg-[#27c93f] border border-black\u002F40 inline-block\">\u003C\u002Fspan>\n      \u003Cspan class=\"ml-2 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">GO\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%2F%2F%20scores.go%0Apackage%20main%0A%0Aimport%20(%0A%09%22bufio%22%0A%09%22fmt%22%0A%09%22os%22%0A%09%22strconv%22%0A)%0A%0Afunc%20main()%20%7B%0A%09scanner%20%3A%3D%20bufio.NewScanner(os.Stdin)%0A%09scores%20%3A%3D%20%5B%5Dint%7B%7D%0A%09for%20scanner.Scan()%20%7B%0A%09%09n%2C%20err%20%3A%3D%20strconv.Atoi(scanner.Text())%0A%09%09if%20err%20!%3D%20nil%20%7B%0A%09%09%09continue%0A%09%09%7D%0A%09%09scores%20%3D%20append(scores%2C%20n)%0A%09%7D%0A%0A%09total%20%3A%3D%200%0A%09if%20len(scores)%20%3E%200%20%7B%0A%09%09for%20_%2C%20s%20%3A%3D%20range%20scores%20%7B%0A%09%09%09total%20%2B%3D%20s%0A%09%09%7D%0A%09%7D%0A%0A%09fmt.Printf(%22count%3A%20%25d%5Cn%22%2C%20len(scores))%0A%09fmt.Printf(%22mean%3A%20%25.1f%5Cn%22%2C%20float64(total)%2Ffloat64(len(scores)))%0A%7D\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed bg-[#24292e]\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\" tabindex=\"0\">\u003Ccode>\u003Cspan class=\"line\">\u003Cspan style=\"color:#6A737D\">\u002F\u002F scores.go\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">package\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">import\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> (\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">bufio\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">fmt\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">os\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#9ECBFF\">\t\"\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">strconv\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">func\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> main\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscanner \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> bufio.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">NewScanner\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(os.Stdin)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tscores \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> []\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">int\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">{}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Scan\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">() {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tn, err \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> strconv.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Atoi\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scanner.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Text\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">())\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tif\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> err \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">!=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> nil\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\t\tcontinue\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\tscores \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">=\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> append\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores, n)\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\ttotal \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\tif\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\"> len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores) \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">>\u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\"> 0\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#F97583\">\t\tfor\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> _, s \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">:=\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\"> range\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> scores {\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t\ttotal \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">+=\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\"> s\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\t}\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"count: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%d\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">\tfmt.\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">Printf\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"mean: \u003C\u002Fspan>\u003Cspan style=\"color:#79B8FF\">%.1f\\n\u003C\u002Fspan>\u003Cspan style=\"color:#9ECBFF\">\"\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">, \u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">float64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(total)\u003C\u002Fspan>\u003Cspan style=\"color:#F97583\">\u002Ffloat64\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(\u003C\u002Fspan>\u003Cspan style=\"color:#B392F0\">len\u003C\u002Fspan>\u003Cspan style=\"color:#E1E4E8\">(scores)))\u003C\u002Fspan>\u003C\u002Fspan>\n\u003Cspan class=\"line\">\u003Cspan style=\"color:#E1E4E8\">}\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n\u003Cdiv class=\"code-block-wrapper code-output my-6 not-prose rounded-xl border-2 border-black dark:border-gray-600 shadow-neo overflow-hidden text-[#e1e4e8] transition-all\" data-output-block>\n  \u003Cdiv class=\"code-block-header flex items-center justify-between px-4 py-2.5 bg-[#1f2428] border-b-2 border-black dark:border-gray-600 font-mono text-xs font-bold text-gray-300 select-none\">\n    \u003Cdiv class=\"flex items-center gap-2\">\n      \u003Cspan class=\"code-output-mark\" aria-hidden=\"true\">&gt;_\u003C\u002Fspan>\n      \u003Cspan class=\"ml-1 font-mono font-bold text-xs uppercase tracking-wider text-gray-300\">Output\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cbutton type=\"button\" class=\"copy-code-btn flex items-center gap-1.5 px-3 py-1 text-xs font-bold bg-[#2f363d] text-gray-200 border-2 border-black dark:border-gray-500 rounded-lg shadow-neo-sm hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none hover:bg-gray-700 transition-all cursor-pointer\" data-code=\"%24%20go%20run%20scores.go%20%3C%20scores.txt%20%7C%20go%20run%20check_main.go%0APASS%20%20line%201%3A%20count%3A%206%0APASS%20%20line%202%3A%20mean%3A%2076.2%0A%0A2%20of%202%20checks%20passed\" title=\"Copy\">\n      \u003Csvg class=\"w-3.5 h-3.5 copy-icon-svg\" fill=\"none\" stroke=\"currentColor\" viewBox=\"0 0 24 24\">\n        \u003Cpath stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Cspan class=\"copy-text\">Copy\u003C\u002Fspan>\n    \u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n  \u003Cdiv class=\"code-block-content p-4 overflow-x-auto text-sm font-mono leading-relaxed\">\n    \u003Cpre class=\"shiki github-dark\" style=\"background-color:#24292e;color:#e1e4e8\">\u003Ccode>\u003Cspan class=\"code-output-cmd\">$ go run scores.go &lt; scores.txt | go run check_main.go\u003C\u002Fspan>\nPASS  line 1: count: 6\nPASS  line 2: mean: 76.2\n\n2 of 2 checks passed\u003C\u002Fcode>\u003C\u002Fpre>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\u003Cp>The checker now exits with status 0, so a script can gate on it.\u003C\u002Fp>\n\u003Cp>I declare a variable in the innermost block that contains every line that reads or writes it. In a deeper block I change it with \u003Ccode>=\u003C\u002Fcode> or \u003Ccode>+=\u003C\u002Fcode>, because \u003Ccode>:=\u003C\u002Fcode> there starts a new variable that ends at the next closing brace.\u003C\u002Fp>\n","\u003Cul>\n\u003Cli>\u003Ccode>package main\u003C\u002Fcode>, \u003Ccode>import\u003C\u002Fcode>, and \u003Ccode>func main\u003C\u002Fcode> are the three parts of a runnable Go file, and a file without \u003Ccode>func main\u003C\u002Fcode> fails with \u003Ccode>function main is undeclared in the main package\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>\u003Ccode>var name type\u003C\u002Fcode> declares without a value, and Go fills the variable with that type&#39;s zero value: \u003Ccode>0\u003C\u002Fcode>, \u003Ccode>&quot;&quot;\u003C\u002Fcode>, \u003Ccode>false\u003C\u002Fcode>, \u003Ccode>0\u003C\u002Fcode>, or a nil slice.\u003C\u002Fli>\n\u003Cli>\u003Ccode>:=\u003C\u002Fcode> declares and assigns in one statement and takes the type from the right-hand side.\u003C\u002Fli>\n\u003Cli>A \u003Ccode>:=\u003C\u002Fcode> inside a block declares a new variable that ends at the closing brace, even when the same name exists outside, which is what shadowing means.\u003C\u002Fli>\n\u003Cli>Go refuses to build a program with a declared and unused variable (\u003Ccode>declared and not used: bonus\u003C\u002Fcode>), but a shadowed variable counts as used, so the compiler stays quiet.\u003C\u002Fli>\n\u003Cli>\u003Ccode>go vet\u003C\u002Fcode> printed nothing at all on the shadowed program, so the wrong mean survived every automatic check.\u003C\u002Fli>\n\u003C\u002Ful>\n",[139,161,181,197,212,229],{"id":140,"title":141,"title_id":142,"slug":143,"excerpt":144,"excerpt_id":145,"has_translation":12,"published_at":146,"reading_time":97,"hidden_from_listing":15,"tags":147,"thumbnail_image":21,"og_image":152,"series":153,"authors":158},48,"What a Linked List Actually Is","Tentang Struktur Data LinkedList","tentang-struktur-data-linked-list","A linked list is a linear chain of nodes, each holding data and a pointer to the next node. Here is what that chain looks like, what it costs next to an array, and the same minimal implementation in Java, Python, and JavaScript.","Linked list adalah rantai linear berisi node, dan setiap node menyimpan data plus pointer ke node berikutnya. Ini bentuk rantainya, ongkosnya dibanding array, dan implementasi paling sederhana dalam Java, Python, serta JavaScript.","2026-11-21T01:00:00.000Z",[148,149,150,151],"struktur-data","linked-list","pointer","konsep","\u002Fog\u002Ftentang-struktur-data-linked-list.png",{"id":154,"title":155,"title_id":156,"slug":157},28,"Linear Data Structures","Struktur Data Linear","asd-struktur-linear",[159],{"authors_id":160},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},{"id":162,"title":163,"title_id":164,"slug":165,"excerpt":166,"excerpt_id":167,"has_translation":12,"published_at":168,"reading_time":169,"hidden_from_listing":15,"tags":170,"thumbnail_image":21,"og_image":172,"series":173,"authors":178},47,"Why Understanding Algorithms and Data Structures Actually Matters","Pentingnya Memahami Algoritma dan Struktur Data","pentingnya-memahami-algoritma-dan-struktur-data","An algorithm is an ordered list of steps, and that order decides how expensive a problem is. The examples are on the back of an instant noodle packet, in a factorial, and behind ctrl+z.","Sebagai konsep fundamental, algoritma menentukan seberapa mahal sebuah masalah diselesaikan. Contohnya ada di bungkus mie instan, di bilangan faktorial, dan di tombol undo.","2026-11-19T01:00:00.000Z",7,[171,148,151,82],"algoritma","\u002Fog\u002Fpentingnya-memahami-algoritma-dan-struktur-data.png",{"id":174,"title":175,"title_id":176,"slug":177},27,"About Algorithms and Data Structures","Tentang Algoritma dan Struktur Data","asd-intro",[179],{"authors_id":180},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},{"id":182,"title":183,"title_id":184,"slug":185,"excerpt":186,"excerpt_id":187,"has_translation":12,"published_at":188,"reading_time":79,"hidden_from_listing":15,"tags":189,"thumbnail_image":21,"og_image":192,"series":193,"authors":194},150,"Java Loops: the Last Price That Never Reached the Sum","Loop Java: Harga Terakhir yang Tidak Pernah Masuk ke Total","java-loops","Four prices add up to 47000, and the cart program prints 36500. The bound is `prices.length - 1`, so the last item is never read while the average is still divided by four.","Empat harga berjumlah 47000, tapi program keranjang mencetak 36500. Batasnya `prices.length - 1`, jadi item terakhir tidak pernah dibaca sementara rata-ratanya tetap dibagi empat.","2026-11-13T01:00:00.000Z",[190,191],"java","loop","\u002Fog\u002Fjava-loops.png",{"id":125,"title":60,"title_id":61,"slug":62},[195],{"authors_id":196},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},{"id":198,"title":199,"title_id":200,"slug":201,"excerpt":202,"excerpt_id":203,"has_translation":12,"published_at":204,"reading_time":79,"hidden_from_listing":15,"tags":205,"thumbnail_image":21,"og_image":207,"series":208,"authors":209},149,"Java switch: the 78 That Came Out as a C","Java switch: 78 yang Keluar sebagai C","java-switch","A grading program marks a paper 78 and prints `grade: C`. `case 7` assigns `B` and then runs into `case 6` because the `break` is missing, and the compiler says nothing about it.","Sebuah program penilaian memberi nilai 78 pada satu lembar ujian lalu mencetak `grade: C`. `case 7` memberi `B` lalu jatuh ke `case 6` karena `break`-nya hilang, dan kompilator tidak mengatakan apa pun soal itu.","2026-11-12T01:00:00.000Z",[190,206],"percabangan","\u002Fog\u002Fjava-switch.png",{"id":125,"title":60,"title_id":61,"slug":62},[210],{"authors_id":211},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},{"id":213,"title":214,"title_id":215,"slug":216,"excerpt":217,"excerpt_id":218,"has_translation":12,"published_at":204,"reading_time":14,"hidden_from_listing":15,"tags":219,"thumbnail_image":21,"og_image":224,"series":225,"authors":226},108,"At 11 a.m. the AI Quota Runs Out, and the Work Stops There","Jam 11 siang kuota AI-nya habis, dan kerjaan berhenti di situ","jam-11-kuota-ai-habis-kerjaan-berhenti","The panel says the usage limit is reached and the work stops, not because it is finished. Three guesses explain it, and all three are wrong: the limit is shaped like a cliff, and the day is built on top of one tool.","Panel di layar bilang batas pemakaian tercapai, dan kerja berhenti di situ. Bukan karena selesai. Ada tiga tebakan kenapa ini terjadi, dan ketiganya salah: batasnya berbentuk tebing, dan harinya dibangun di atas satu alat.",[220,221,222,223],"ai","tooling","rate-limit","produktivitas","\u002Fog\u002Fjam-11-kuota-ai-habis-kerjaan-berhenti.png",{"id":24,"title":25,"title_id":26,"slug":27},[227],{"authors_id":228},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},{"id":74,"title":75,"title_id":21,"slug":76,"excerpt":77,"excerpt_id":21,"has_translation":15,"published_at":78,"reading_time":79,"hidden_from_listing":15,"tags":80,"thumbnail_image":21,"og_image":84,"series":230,"authors":231},{"id":86,"title":56,"title_id":57,"slug":58},[232],{"authors_id":233},{"id":109,"name":110,"slug":111,"role":112,"profile_picture":21},[235,239,242,245,248],{"text":236,"depth":237,"id":238},"The three parts of a Go file",2,"the-three-parts-of-a-go-file",{"text":240,"depth":237,"id":241},"Declaring variables","declaring-variables",{"text":243,"depth":237,"id":244},"When := makes a second variable","when-makes-a-second-variable",{"text":246,"depth":237,"id":247},"The one rule the compiler enforces","the-one-rule-the-compiler-enforces",{"text":249,"depth":237,"id":250},"Check the fix with a second program","check-the-fix-with-a-second-program",1794557078063]