Results 1 to 5 of 5

Thread: [Idle] Go Booleans

  1. #1
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default [Idle] Go Booleans

    I am trying to get the bool to proc the variable change in http://play.golang.org/p/Of8mVuTTPw. Why is it not working?

  2. #2
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    it doesnt restart when you mention milk on line 18. all it does is look for the current value of milk. try putting "eggs = true" before the if statement

    calling a function after eggs has been set would probably give you the result you were looking for
    Code:
    package main
    
    import "fmt"
    
    func main() {
    	var eggs bool
    	
    	buymilk := func() int {
    		if eggs == true {
    			return 6
    		} else {
    			return 1
    		}
    	}
    	//milk := buymilk()
            eggs = true
    	fmt.Println("Mom asked me to buy many bottles of milk?", buymilk())
    }
    this code calls a function before eggs has been set
    Code:
    package main
    
    import "fmt"
    
    func main() {
    	var eggs bool
    	
    	buymilk := func() int {
    		if eggs == true {
    			return 6
    		} else {
    			return 1
    		}
    	}
    	milk := buymilk()
            eggs = true
    	fmt.Println("Mom asked me to buy many bottles of milk?", milk)
    }
    Last edited by wiel; Jul 28, 2013 at 09:18 AM. Reason: eggs
    1337

  3. #3
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    Quote Originally Posted by wiel View Post
    it doesnt restart when you mention milk on line 18. all it does is look for the current value of milk. try putting "eggs = 6" before the if statement

    calling a function after eggs has been set would probably give you the result you were looking for
    I don't know how. Assigning a value to a boolean type would change it to char or int.
    Code:
    package main
    
    import "fmt"
    
    func main() {
    	var eggs bool
    	
    	buymilk := func() int {
    		if eggs == true {
    			return 6
    		} else {
    			return 1
    		}
    	}
    	//milk := buymilk()
            eggs = true
    	fmt.Println("Mom asked me to buy many bottles of milk?", buymilk())
    }
    //fits very well! #GJ!
    this code calls a function before eggs has been set
    Code:
    package main
    
    import "fmt"
    
    func main() {
    	var eggs bool
    	
    	buymilk := func() int {
    		if eggs == true {
    			return 6
    		} else {
    			return 1
    		}
    	}
    	milk := buymilk()
            eggs = true
    	fmt.Println("Mom asked me to buy many bottles of milk?", milk)
    }
    So, whatever is done has to be before the decision process? Noted.

  4. #4
    Join Date
    Mar 2006
    Posts
    325
    Rep Power
    0

    Default

    I don't know how. Assigning a value to a boolean type would change it to char or int.
    oh right. that should be eggs = true/false

    the code runs in a sequence, not a loop so the if statement would only run once
    1337

  5. #5
    Join Date
    Jul 2002
    Posts
    1,395
    Rep Power
    0

    Default

    Quote Originally Posted by wiel View Post
    oh right. that should be eggs = true/false

    the code runs in a sequence, not a loop so the if statement would only run once
    http://play.golang.org/p/K37nHYSErb seems so far from what the algorithms say though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •