Advertisement
ipwxy

If Statements

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