Contenu connexe
Plus de Program in Interdisciplinary Computing (20)
08 boolean expressions
- 1. Super Powerful Boolean Expressions LIS4930 © PIC ‘And’ and ‘Or’ Operators (&&, ||) If the price range is between $300 and $400 then choose X: if ( price >= 300 && price < 400) { camera = “X”; } What if the returned results were too large, and you can only looking or brands “A” or “B”. if ( brand.equals(“A”) || brand.equals(“B”) ) { //do stuff for only brand A or brand B }
- 2. Super Powerful Boolean Expressions LIS4930 © PIC Not equals ( != and ! ) Let’s say that you have a logic like, “of the ten available comdels, a certain thing is true for all but one”. if ( model != 2000 ) { //do non-model 2000 stuff } or for comparing objects like strings… if ( !brand.equals(“X”) ) { //do non-brand X stuff }
- 3. Super Powerful Boolean Expressions LIS4930 © PIC Boolean expressions can get really big and complicated: if ((zoomType.equals(“optical”) && (zoomDegree >= 3 && zoomDegree <= 8)) || (zoomType.equals(“digital”) && (zoomDegree >= 5 && zoomDegree <= 12))) { //do appropriate zoom stuff }