John wants to check if a number is even or odd. Which control structure should he use to make the decision?

  • For Loop
  • If-Else Statement
  • Switch Statement
  • While Loop
John should use an "If-Else Statement" to determine whether a number is even or odd. The "If-Else" control structure allows him to evaluate a condition (e.g., number % 2 == 0) and execute different code blocks based on whether the condition is true or false. In this case, he can check if the number is divisible by 2 to decide if it's even or odd.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *