// example boolean expressions x > 2 0 <= y && y <= 10 ! (0 <= y && y <= 10 ) button.isVisible()A boolean expression evaluates to true or false. You can store it in a boolean variable e.g.
// storing a boolean expression in a variable boolean whether = x > 2;You can print out a boolean variable. You don’t need an if to do it.
// displaying a boolean variable on the console System.out.println( whether );You can use a boolean variable in an if later rather than recalculating the expression.
// referencing a boolean variable in an if if ( whether ) makeDate(); if ( ! whether && done() ) finish();
// ILLEGAL IN JAVA!! int is not the same as boolean int seen = button.isVisible(); if ( seen ) doSomething();You must write:
// boolean must be used in Java where in C you could use an int. boolean visible = button.isVisible(); if ( visible ) doSomething(); // or using an int with int-style syntax. int seen = button.isVisible() ? 0 : 1; if ( seen != 0 ) doSomething();
// Goony stuttering code often written by newbies if ( whether == true ) // or if ( whether == false ) // or if ( whether == true && done == false )Don’t stutter, just write:
// terse code if ( whether ) // or if ( !whether ) // or if ( whether && !done )
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.16] | The information on this page is for non-military use only. | ||
| You are visitor number 25,891. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/boolean.html | J:\mindprod\jgloss\boolean.html | ||