Conditional operator: ?

The question mark is the conditional operator. It is a ternary operator, it has three parts: the condion, the result if true, and the result if false.

The syntax is (Boolean expression)? true value: false value;

The conditional operator is used instead of if/else in very simple situations.

Please study the material at each of the links below.

  1. Print pass or fail
  2. Tests if a month is valid with variable
  3. Displays if a month is valid
  4. Prints two numbers in order
  5. Finds the smallest
  6. Calculate tip using conditional
Like us on Facebook:


OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 23 2017 17:41:23.