When do we use bool variable ? | Sololearn: Learn to code for FREE!


When do we use bool variable ?

9/19/2017 8:50:05 PM

Ahmad Alzohaile

7 Answers

New Answer


When a true/false value is required to be stored/tracked http://www.learncpp.com/cpp-tutorial/26-boolean-values/


Any time you have a yes or no question/answer.


I used one here to verify my number. https://code.sololearn.com/cF7iOkU73BYy/?ref=app


Think of it as a fork in the road of your code. If true, do one thing, if false do something else. Boolean variables should be named appropriately too - by convention you should prefix your variable names with "Is". For example, if determining that the side of a coin is heads I might create the variable name "IsHeads" .


In any flow control statements (if/else, switch, loops...)



for true or false