• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

still not 100% clear on boolean logic  RSS feed

 
Ranch Hand
Posts: 177
1
  • Mark post as helpful
  • send pies
  • 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: 20655
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • 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: 6697
464
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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: 6697
464
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!