Advertisement
Guest User

If Statements

a guest
Jun 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. /**
  2. if statements allow developers branch code, executing code only if a condition is true.
  3. */
  4.  
  5.     int number = 5;
  6.  
  7.     if(number < 10) {
  8.         // execute code
  9.     }
  10.  
  11. /**
  12. if else statements allow you to execute code if the condition is not true.
  13. */
  14.  
  15.     if(number < 10) {
  16.         // execute if true
  17.     } else {
  18.         // execute if false
  19.     }
  20.  
  21. /**
  22. You can combine conditions using && and ||.
  23.  
  24. && represents AND.
  25. Both conditions must be true for the code to execute.
  26. */
  27.  
  28.     // if (number < 10 AND number > 0)
  29.     if(number < 10 && number > 0) {
  30.        
  31.     }
  32.  
  33. /**
  34. || represents OR.
  35. Only one condition must be true for the code to execute.
  36. */
  37.     // if (number < 10 OR number > 0)
  38.     if(number < 10 || number > 0) {
  39.        
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement