mirror of
https://github.com/golang/go
synced 2024-11-25 16:47:56 -07:00
58d287e5e8
We need to make sure that the terminating comparison has the right sense given the increment direction. If the increment is positive, the terminating comparsion must be < or <=. If the increment is negative, the terminating comparison must be > or >=. Do a few cleanups, like constant-folding entry==0, adding comments, removing unused "exported" fields. Fixes #26116 Change-Id: I14230ee8126054b750e2a1f2b18eb8f09873dbd5 Reviewed-on: https://go-review.googlesource.com/121940 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
19 lines
305 B
Go
19 lines
305 B
Go
// run
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
func main() {
|
|
s := []int{0, 1, 2}
|
|
i := 1
|
|
for i > 0 && s[i] != 2 {
|
|
i++
|
|
}
|
|
if i != 2 {
|
|
panic("loop didn't run")
|
|
}
|
|
}
|