The first value returned by range is the index, not the value. What you need is:

func main() {
    one := uint(1)
    ones := []uint{1, 1, 1}
    for _, x := range ones {
        if x != one {
            print("ERR")
        }
    }
}
Answer from Ainar-G on Stack Overflow
🌐
Go
go.dev › tour › basics › 11
A Tour of Go
bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr byte // alias for uint8 rune // alias for int32 // represents a Unicode code point float32 float64 complex64 complex128
🌐
GitHub
github.com › golang › go › issues › 66967
spec: a valid range uint(maxUint) is not accepted · Issue #66967 · golang/go
April 22, 2024 - The range expression uint(maxUint) is an integer expression but cannot be assigned to an int variable, yet this code is permitted. Or perhaps the intent was that the assignability requirement to int is only present if the expression x is untyped, ...
Author   golang
🌐
Ado
ado.xyz › blog › go-numerical-type-ranges
Go Numerical Type Ranges - Ado.xyz
May 9, 2020 - Again, similar to the default int variable for 32-bit systems, the ranges you can represent is between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807. Much like int, the uint type has a range that is dependent on the underlying ...
🌐
Go Tutorial
golangbot.com › types
Basic Data Types in Go | golangbot.com
May 5, 2024 - Please read Golang tutorial part 3: Variables of this series to learn about variables. The following are the basic data types available in Go · bool · Numeric Types · int8, int16, int32, int64, int · uint8, uint16, uint32, uint64, uint · ...
🌐
Rotational
rotational.io › blog › ranges-of-integer-data-types
Rotational Labs | Ranges of Integer Data Types
So without further ado, here are ... = 1<<63 - 1 MinInt64 int64 = -1 << 63 MaxUint8 uint8 = 1<<8 - 1 MaxUint16 uint16 = 1<<16 - 1 MaxUint32 uint32 = 1<<32 - 1 MaxUint64 uint64 = 1<<64 - 1 ) // Complement method (system specific) ...
🌐
Golang Docs
golangdocs.com › home › integers in golang
Integers in Golang - Golang Docs
December 24, 2019 - uint16 (16-bit unsigned integer whose range is 0 to 65535 )
🌐
ZetCode
zetcode.com › golang › builtins-uint-type
Understanding the uint Type in Golang
May 8, 2025 - The uint type represents unsigned integers in Go. Unlike signed integers, uint values are always positive. They provide a larger positive range than their signed counterparts at the same bit size.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › understanding-data-types-in-go
Understanding Data Types in Go | DigitalOcean
May 1, 2019 - Because an int type needs to support both positive and negative values, an 8-bit integer (int8) will have a range of -128 to 127, for a total of 256 unique possible values. Go has the following architecture-independent integer types: uint8 unsigned 8-bit integers (0 to 255) uint16 unsigned ...
🌐
Go Packages
pkg.go.dev › builtin
builtin package - builtin - Go Packages
Range: -9223372036854775808 through 9223372036854775807. ... rune is an alias for int32 and is equivalent to int32 in all ways. It is used, by convention, to distinguish character values from integer values. ... string is the set of all strings of 8-bit bytes, conventionally but not necessarily ...
🌐
LabEx
labex.io › tutorials › go-numerical-types-in-golang-149067
Numerical Types in Golang | LabEx
They are both 8-bit integers and can represent 256 values. In the unsigned integer type uint8, the range it can represent is from 0 to 255, while in the signed integer type int8, the range it can represent is from -128 to 127.
🌐
Boot.dev
blog.boot.dev › golang › default-native-types-golang
Don't Go to Casting Hell - Use Default Native Types in Go | Boot.dev
May 21, 2020 - In all of the above cases, the choice of specific sub-types are based on range and precision. int8 can store values between -128 and 127, while int64 ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
🌐
Reddit
reddit.com › r/golang › weird type conversion (uint8 to i32) using range function ?
r/golang on Reddit: Weird type conversion (uint8 to i32) using range function ?
December 21, 2023 -

Hello gophers!

I encountered a weird conversion when iterating over strings.
I used "résumé" as string following a youtube video.

So what happend was, that it seems that go converted uint8 to int32 when using the range function.

And I am unsure why it did that, because u8 should be enough no ?
Also when checking what values the runes resemble I did get a different value for 'é' back ?
Maybe someone can clear this up for me, thanks in advance.

func main() {
var myString = "résumé"

var indexed = myString[0]
fmt.Printf("%v %T\n", indexed, indexed)

indexed = myString[1]
fmt.Printf("%v %T\n", indexed, indexed)

}

Output:
Value: 114, Type: uint8
Value: 195, Type: uint8 // <- This value seems to be wrong !

And then using range it changed type to int32 for some reason ?
Can someone explain why that is ?

func main() {
/* ... */

// range does encode it to int32 ?
for index, value := range myString {
    fmt.Printf("Index: %v, Value: %v, Type: %T\n", index, value, value)
}

}

Output:
Index: 0, Value: 114, Type: int32
Index: 1, Value: 233, Type: int32
Index: 3, Value: 115, Type: int32
Index: 4, Value: 117, Type: int32
Index: 5, Value: 109, Type: int32
Index: 6, Value: 233, Type: int32

Then checking backwards what runes i get from uint8 using the int32 values i get the correct ones with 233 weirdly enough.
Any ideas why i get "wrong" value of 'e' from uint8 in the first place ?

func main() {
/* ... */

var rune_195 = string(uint8(195))
fmt.Println(rune_195)
var rune_233 = string(uint8(233))
fmt.Println(rune_233)

}

Output:
Ã
é

🌐
W3Schools
w3schools.com › go › go_integer_data_type.php
Go Integer Data Types
This example will result in an error because 1000 is out of range for int8 (which is from -128 to 127): package main import ("fmt") func main() { var x int8 = 1000 fmt.Printf("Type: %T, value: %v", x, x) } Result: ./prog.go:5:7: constant 1000 ...
🌐
CalliCoder
callicoder.com › golang-basic-types-operators-type-conversion
Golang Basic Types, Operators and Type Conversion | CalliCoder
February 18, 2022 - It is 32 bits wide on a 32-bit system and 64-bits wide on a 64-bit system. When you are working with integer values, you should always use the int data type unless you have a good reason to use the sized or unsigned integer types.
🌐
Go
go.dev › src › builtin › builtin.go
- The Go Programming Language
26 type uint8 uint8 27 28 // uint16 is the set of all unsigned 16-bit integers. 29 // Range: 0 through 65535. 30 type uint16 uint16 31 32 // uint32 is the set of all unsigned 32-bit integers. 33 // Range: 0 through 4294967295. 34 type uint32 uint32 35 36 // uint64 is the set of all unsigned ...
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › golang integer types explained [in-depth tutorial]
Golang Integer Types Explained [In-Depth Tutorial] | GoLinuxCloud
May 11, 2023 - uint64: An unsigned 64-bit integer with a range of 0 to 18,446,744,073,709,551,615. These different integer data types in Golang allow you to optimize your code by choosing the most suitable type based on the range and sign requirements, which ...