• We want our program to be able to execute statements conditionally, based on the value of data entered by the user.
  • An if structure can be used for this purpose.
  • The if structure has a condition that is either true or false.
  • If the condition is true, then a target statement is executed.
  • If the condition is false, then the target statement is not executed.
  • The condition in if structures can test 2 quantities to see if:
    • they are equal
    • one quantity is less than the other
    • one quantity is less than or equal to the other
  • There are 6 such operators in all:

     

    JavaEnglish
    x == yIs x equal to y ?
    x != yIs x not equal to y ?
    x < yIs x less than y ?
    x > yIs x greater than y ?
    x <= yIs x less than or equal to y ?
    x >= yIs x greater than or equal to y ?
  • If you embed a space in these operators (e.g., "! ="), it causes a syntax error.
  • Reversing the order of the characters that make up an operator (e.g., "=>") causes a syntax error.s