On 11 September 2017 at 17:56, CampNowhere <urbanconfeder...@gmail.com> wrote: > I am a C developer and am trying to pick up Go. > > My question is this. C doesn't "care" about truthfulness, it just cares > about zero and non-zero when evaluating a logical AND operator. So something > like the following in C is totally kosher: > > int a = 10; > int b = 20; > > while(a && b) > { > do_something(); > } > > However, Go requires blloean values used with the logical AND operator ... > so my necessary code change for Go implementation becomes the following: > > var a,b int = 10,20 > > for (a != 0) && (b != 0) { > do_something() > } > > Is doing things this way absolutely necessary? It seems a lot clunkier and > less elegant.
The required syntax is actually marginally simpler: for a != 0 && b != 0 { } I very much like Go's explicit use of booleans. One advantage is that you always know the exact value of any true/false value, so you can be sure that: if a && b { if a == b { print("ok") } } will always print "ok". In C it may not - you need to remember to do: if((a != 0) == (b != 0)){ which is sometimes easy to forget. Having explicit bools makes the language cleaner and easier to understand IMHO. That doesn't mean I'm against having an explicit bool to int conversion, though. > > -- > 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 golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.