FAQ
// test uint8 loop on Go version 1.6
package main

import "fmt"

func main() {
for i := 250; i <= 255; i++ {
fmt.Println("i=", i)
}
for j := uint8(250); j > 0; j++ {
fmt.Println("j=", j)
}
/* this will cause infinite loop
for k := uint8(250); k<=255; k++ {
fmt.Println("k=", k)
}
*/
}

All these three paragraph are trying to do the same thing.

In the 'k' sample, I must re-write my code as 'j' otherwise it will caused
infinite loop.
I'm wonder if there any 'lint option' could check this? Or, just treat it
as compiler error?

https://play.golang.org/p/61neJbuQ1U

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Wojciech S. Czarnecki at Feb 28, 2016 at 5:33 pm
    Dnia 2016-02-28, o godz. 08:18:20
    dlin <[email protected]> napisał(a):

    I know of no go linters that can spot bugs in otherwise valid
    program logic. (k <= 255 is always true for 8 bit uint).

    for k := uint8(250); k<=255; k++ {
    fmt.Println("k=", k)
    }
    --
    Wojciech S. Czarnecki
            ^oo^ OHIR-RIPE

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.
  • Nate Finch at Feb 29, 2016 at 5:02 pm
    I don't know, there's already some go vet checks for comparisons that will
    always be true or false. It doesn't seem unreasonable to add another.
      There's pretty much never a time when this isn't a programmer mistake. If
    you really want an infinite loop, you'd just leave out the center
    expression.
    On Sunday, February 28, 2016 at 12:33:52 PM UTC-5, ohir wrote:

    Dnia 2016-02-28, o godz. 08:18:20
    dlin <[email protected] <javascript:>> napisał(a):

    I know of no go linters that can spot bugs in otherwise valid
    program logic. (k <= 255 is always true for 8 bit uint).

    for k := uint8(250); k<=255; k++ {
    fmt.Println("k=", k)
    }
    --
    Wojciech S. Czarnecki
    ^oo^ OHIR-RIPE
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 28, '16 at 4:18p
activeFeb 29, '16 at 5:02p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase