Basic Conditions - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Basic Conditions

Description:

Basic Conditions. Challenge: Ask the user his/her name. If it's 'Wally,' jeer him ... Allows the computer to 'make decisions' Based on a condition ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 17
Provided by: wallyC
Category:
Tags: basic | conditions | jeer

less

Transcript and Presenter's Notes

Title: Basic Conditions


1
Basic Conditions
2
Challenge
  • Ask the user his/her name
  • If its Wally, jeer him
  • Pause video and try on your own.

3
Conditional Branching
  • Allows the computer to make decisions
  • Based on a condition
  • Embedded into some other programming structure

4
Condition
  • Expression
  • Can be evaluated to true or false
  • Often compares a variable to a value
  • Sometimes compares two variables

5
Comparison Operators
  • Equals
  • ! Not Equal
  • lt Less than or equal to
  • gt Greater than or equal to
  • lt Less than
  • gt Greater than

6
If Statement
  • Checks a condition
  • Begins a block of code
  • If condition is true, executes all code in block
  • If condition is false, skips code block

7
If example
  • If its raining
  • Wear a raincoat
  • End if

8
Challenge Algorithm
  • New program hiWally by me
  • New variable userName string starts with
  • Ask users name, store in userName
  • If userName is equal to Wally
  • Output You Bovine
  • End if
  • End Program

9
Challenge
  • Modify the Wally program so it says one thing if
    the users name is Wally, and a more benign
    greeting if its someone else
  • Pause video and try on your own

10
Using an Else Clause
  • Else is a useful addition to If statements.
  • Else allows you to set up another block of code
    to execute if the condition is false

11
If-Else Example
  • If its raining
  • Wear a raincoat
  • Else
  • Wear a sweater
  • End if

12
Challenge Algorithm
  • New program wallyOrNot by me
  • New variable userName string starts with
  • Ask users name, store in userName
  • If userName is equal to Wally
  • Output You Bovine
  • Else
  • Output Do I know you userName ?
  • End if
  • End Program

13
(No Transcript)
14
Challenge Algorithm
15
(No Transcript)
16
Code
  • My code
Write a Comment
User Comments (0)
About PowerShow.com