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 8840779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:32:39+00:00 2026-06-14T10:32:39+00:00

For the sake of type strictness I sometimes store my sizes as uint’s when

  • 0

For the sake of type strictness I sometimes store my sizes as uint’s when a size cannot be negative. When used in for loops, I want it to look like this:

var size uint32 = 8
for i := 0; i < size; {
    n := //doesn't matter how how this value is determined
    i += n
}

However, I get the following error message: invalid operation: i < size (mismatched types int and uint32)

Rewriting the for loop to specify a type like this:

for var i uint32 = 0; i < size; {

Yields this compiler error: syntax error: var declaration not allowed in for initializer

The only ways around these errors are:

for i := 0; uint32(i) < size; {

or

var i uint32 = 0
for i < size {

The first on is inefficient because I am casting on every iteration and the second one is less elegant. Is there a better way to do this?

  • 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-14T10:32:40+00:00Added an answer on June 14, 2026 at 10:32 am

    You can do:

    for i := uint32(0); i < size; {
        //whatever
    }
    

    Generally, I don’t recommend using an unsigned integer even when size can never be negative. I don’t know of any upside. I only use unsigned integers when I am intentionally overflowing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an enum type (say for arguments sake CarModel ), used throughout an
I've defined a custom error type that I want to use with the Error
Object graph for type '[type]' contains cycles and cannot be serialized if reference tracking
I have a few procedures, for simplicity sake, look like the following: public string
For sake of simplicity, let's assume I want to write an extension method for
For the sake of post processing on a method, I want to import an
If I have the following 3 classes to hide the data type and store
For the sake of simplicity, lets say I have a CustomerViewModel and I want
I have a few procedures that, for simplicity's sake, look like the following: public
Just for learning's sake, I tried in java doc but I did not find

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.