Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9092083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:45:26+00:00 2026-06-16T22:45:26+00:00

EDIT This was due to a stupid error in my part, but the question

  • 0

EDIT This was due to a stupid error in my part, but the question is worth keeping around in case someone else does this.

I would hope that this works:

var xs []uint8
var x uint8
for x = range xs {

}

But I get the error:

cannot assign type int to x (type uint8) in range

i.e. (as I understand it) the range, even though it is operating on a slice of uint8, is trying to use int as the iterated value.

I have looked through the language spec, the relevant bit:

Range expression                          1st value          2nd value (if 2nd variable is present)

array or slice  a  [n]E, *[n]E, or []E    index    i  int    a[i]       E

so I would expect it to be E the ‘parameterised type’*, in this case uint8 not int.

Have I grasped onto the wrong end of the stick? Is there a bit of documentation that I missed? Or can I really not iterate over a uint8 slice with a uint8 variable?

*I know it’s not really a generic parameterised type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:45:27+00:00Added an answer on June 16, 2026 at 10:45 pm

    range returns an index into a collection and possibly the value at that position:

    range keyword The range keyword allows you to iterate over items of a
    list like an array or a map. For understanding it, you could translate
    the range keyword to for each index of. When used with arrays and
    slices, it returns the integer index of the item.
    (tutorial)

    sample code:

    package main
    
    import "fmt"
    
    func main() {
        var xs []uint8 = []uint8{255, 254, 253}
        var idx int
        var ui8 uint8
        for idx, ui8 = range xs {
            fmt.Println(idx, ui8)
        }
    }
    

    output:

    0 255
    1 254
    2 253
    

    P.S.:

    Perhaps a look at Javascript will make Go’s approach less strange:

    % a = [255, 254, 253]
    255,254,253
    % for (x in a) { print(x, " ", a[x]); }
    0 255
    1 254
    2 253
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This question was asked due to inadequate knowledge of the EventMachine . With
EDIT: This question is due to a big lack of understanding how Interface Builder
Edit: this question was asked due to my misunderstanding. Proceed with caution, as reading
I have this ajax call, which works for the most part, but it does
THIRD EDIT: I now believe that this problem is due to a SOAP version
edit This question is solved! Having something weird. I'm using html { font-size: 100%
Edit: this question is outdated. The jsonlite package flattens automatically. I am dealing with
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
Edit This question has gone through a few iterations by now, so feel free
EDIT: This question is a duplicate of What is the difference between managed and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.