PD1: Chapter 4: Selections

Cards (77)

  • What is the Boolean datatype based on?
    Mathematics
  • What does Boolean algebra describe?
    The mathematics of reasoning about true and false propositions
  • What are the two values of the Boolean datatype?
    true and false
  • How must Boolean values be written in C#?
    In lowercase
  • How does the Boolean datatype in C# differ from C regarding truth values?
    In C#, numerical values cannot be used as Boolean values
  • What is the keyword for the Boolean datatype in C#?
    bool
  • How are Boolean values generated in C#?
    By comparing two numeric or char values using comparison operators
  • What operator is used for equality testing in C#?
    ==
  • What does the inequality operator != do in C#?
    Tests if two values are not equal
  • Which operators are used for comparison in C#?
    <, <=, >, >=
  • What is the result of the expression 3 < 2.7f in C#?
    false
  • What does the expression 3 == 3.0f yield in C#?
    true
  • Can comparison operators be used to compare String values in C#?
    No
  • How can one compare String values in C#?
    Using the CompareTo method
  • What does CompareTo return if the executing string is equal to the argument?
    0
  • What does CompareTo return if the executing string is alphabetically less than the argument?
    A value less than zero
  • What does CompareTo return if the executing string is alphabetically more than the argument?
    A value greater than zero
  • Why can't CompareTo return a Boolean value?
    Because there are three possible outcomes
  • What are the three Boolean operators in C#?
    not, and, or
  • What does the not operator do in C#?
    It negates a Boolean value
  • How is the and operator represented in C#?
    With two ampersands (&&)
  • What is the behavior of the and operator (&&) in C#?
    It yields true if both operands are true
  • What is the behavior of the or operator (||) in C#?
    It yields true if at least one operand is true
  • What is a Boolean expression?

    An expression that yields a Boolean result
  • What is an example of a Boolean expression?
    Testing for equality using the == operator
  • What does the ternary conditional operator do?
    It takes three operands and returns one based on a Boolean condition
  • When is the ternary conditional operator useful?
    To avoid writing an if-else statement
  • What happens if the first operand of the ternary operator is true?
    The result is the second operand
  • What happens if the first operand of the ternary operator is false?
    The result is the third operand
  • What is the significance of the order of nested if statements?
    The outcome of the program changes if the order changes
  • What does the switch command allow for in C#?
    Faster execution compared to nested if else statements
  • What is the output of the DisplayMeasurement function when measurement is less than 0.0?
    "Measured value is {measurement}; too low."
  • What is the output of the DisplayMeasurement function when measurement is greater than 15.0?
    "Measured value is {measurement}; too high."
  • What is the output of the DisplayMeasurement function when measurement is NaN?
    "Failed measurement."
  • What is the purpose of the break statement in a switch case?
    To exit the switch statement
  • What does the case statement do in a switch?
    It defines a specific condition to match
  • What is the syntax for a switch statement in C#?
    switch (expression) { case value: statement; }
  • What is the role of the Console.WriteLine method in the DisplayMeasurement function?
    To output the measured value to the console
  • What is the significance of the curly braces in an if statement?
    They define a block of code to be executed
  • What does the else statement do in an if-else structure?
    It executes a block of code if the if condition is false