• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

still not 100% clear on boolean logic

 
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,

its one thing im just not clear on. Variable names and logic for boolean problems. I would really like to understand this properly.

lets say i have a menu system:
1) Cars
2) Vans
3) Bikes
4) Exit system

now i want to write code to handle the menu

i am thinking like this



is that correct? i seem to get names for variables in these statements a bit awkwardly done so im practicing them.
Would like to learn the real general rule of thumb how you guys do it.

any info or thoughts would be amazing!

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, in Boolean logic, you can only be 100% clear or you're 0% clear. That's logic.

Actually there are other logical systems that allow for conditions that are less stark, but when computers became widespread, people stopped using them. Especially in politics.  

Your example is fundamentally correct for Python. Although I think the parentheses are optional. That is, you should be able to say:


And, while Python doesn't care what you name your control variable, some would recommend calling it something like "isUserSelecting" or "userIsSelecting". Which highlights the boolean nature of the variable. And since Python isn't into explicit typing the way that Java and C/C++ are, that's not a bad thing.
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:while (userSelecting)


What do you think, would that work better? "while user did not press to exit system"

Other than that, please explain, how would you tell your program what is that "while user selecting"?
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

wayne brandon wrote:while (userSelecting)


What do you think, would that work better? "while user did not press to exit system"

Other than that, please explain, how would you tell your program what is that "while user selecting"?


I might take back this my comment. Now thinking that maybe not a bad idea to invert that phrase and use as OP suggested by hiding details how user finished selection.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic