CIUC- Creating Interactivity in Programming Using Conditionals Overview

 

Creating Interactivity in Programming Using Conditionals

Most programs that are created or played require interactivity or a response from the user. These programs perform different actions based on what is happening in the program. This type of program requires the use of conditional control structures. Conditional statements make a decision by asking a question and will perform an action based on the answer. Examples would be:

            • Has a button been clicked?
        • Has a key been pressed?
        • Has one thing touched another thing?

You can see that these are questions that result in either a true or false answer. Conditionals will execute when the answer is true. You also have the choice to make something else happen if the answer is false. Other conditional statements require relational operators and boolean operators to help them make the decision.

  • Is the x position > 250?
  • Is the x position > 250 and Has a button been clicked?

In this module, you will learn to create algorithms using conditionals that will be used to create programs for creative expression and to solve problems.

Essential Questions

  • How do you create an interactive program?
  • What is an event driven program?
  • What is an event handler function?
  • How are conditionals used in an interactive program?

Key Terms

boolean - data type that stores only a true or false

boolean expression -  an expression that evaluates to true or false

boolean logic gate - a collection of transistors and resistors that implement Boolean logic operations in a circuit

conditional control structure - a type of control structure used in programming that asks a question and performs an action based on whether the answer to the question is true or false; also called a decision structure

relational operators - operators (==, <, <=, >, >=, !=) that can be used to form a boolean expression

truth table - a table that shows the possible outcomes of two expressions joined by a logical operator

event driven programming - interactive programming that changes behavior in response to events

event handler function - functions or methods that listen for an event and respond to it

event - action or occurrence detected by the program usually triggered by the user clicking the mouse, or pressing a key on the keyboard, or a condition being met

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION