Advertisement
Guest User

Code 3

a guest
Jun 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. // This code outputs:
  2. // 0 0 false false
  3. // A bug?
  4.  
  5. // Note: now both calls to hasBlock at else branch return false, even though such result is not possible due to the if expression.
  6. package main
  7.  
  8. import (
  9. "fmt"
  10. )
  11.  
  12. func hasBlock(x, y int) bool {
  13. if x < 0 || x >= 1 {
  14. return false
  15. }
  16. return true
  17. }
  18.  
  19. func main() {
  20. ok := false
  21.  
  22. for x := 0; x < 1; x++ {
  23. for y := 0; y < 1; y++ {
  24. if !hasBlock(x - 1, y) {
  25. ok = true
  26. } else {
  27. fmt.Println(x, y, hasBlock(-1, 0), hasBlock(x - 1, y))
  28. }
  29. }
  30. }
  31.  
  32. if !ok {
  33. fmt.Println("A bug?")
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement