While Loops and If-Else Structures

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

ROBOTC for CORTEX While Loops Part 1
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
While Loops and If-Else Structures
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Remote Control- RobotC
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Testbed: Exercises.
ROBOTC for VEX Online Professional Development
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
Mindstorm NXT-G Introduction Towson University Robotics.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Vex Robotics program three: using motors and sensors together.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Sensor Information: while loops and Boolean Logic.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
FOP: While Loops.
Programming Design ROBOTC Software Principles Of Engineering
Variables and Functions
INTRODUCTION TO ROBOTICS Part 5: Programming
CHAPTER 4 DECISIONS & LOOPS
Variables and Functions
Variables and Functions
ROBOTC for VEX Online Professional Development
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Programming Design ROBOTC Software Computer Integrated Manufacturing
Expressions and Control Flow in JavaScript
Variables and Functions
Movement using Shaft Encoders
Using Encoders to go Straight
Programming – Touch Sensors
Variables and Functions
RobotC Sensors.
Variables and Functions
Variables and Functions
Variables and Functions
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Variables and Functions
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
Multitasking Emergency Stop Computer Integrated Manufacturing
Three Special Structures – Case, Do While, and Do Until
Programming Design ROBOTC Software Principles Of Engineering
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Conditional Logic Presentation Name Course Name
RobotC While loop When and how to use the while loop
if-else Structures Principles of Engineering
Automation with RobotC
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Automation with RobotC
Robotics Programming Using Shaft Encoders
Selections and Loops By Sarah, Melody, Teresa.
While Loops and If-Else Structures
Programming Design ROBOTC Software Principles of Engineering
While Loops And If-Else Structures
Presentation transcript:

While Loops and If-Else Structures ROBOTC Software Principles of Engineering © 2012 Project Lead The Way, Inc.

While loops While loop is a structure within ROBOTC Presentation Name Course Name Unit # – Lesson #.# – Lesson Name While loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain condition remains true Three main parts to every while loop The word “while” The condition Commands to be repeated

1. The word while Every while loop begins with the keyword while

2. The condition Condition controls how long or how many times a while loop repeats When condition is true, the while loop repeats When condition is false, the while loop ends and the remainder of the program executes Condition is checked once every time the loop repeats just before the commands between curly braces run

3. Commands to be repeated Commands between curly braces will repeat while condition is true Program checks at the beginning of each pass through the loop

Programming - Boolean logic Program decisions are always based on questions Only two possible answers yes or no true or false Statements that can be only true or false are called Boolean statements Their true-or-false value is called a truth value.

Boolean logic

Boolean logic

Writing a condition: Example While the bump switch is not pressed: right motor is on at power value 63 AND left motor is on at same value.

Timers Loop control Solution: Timers Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Timers Loop control Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? Nowhere! We need something else. Solution: Timers Internal stopwatches (4 available) Like encoders, timers should be cleared before they are used. Be careful: Don’t clear a timer in a timed loop. Clearing timers within a loop may continually reset the timers, which may create an infinite loop.

Presentation Name Course Name Unit # – Lesson #.# – Lesson Name Timers Timer T1 is used as the condition for the while loop, which will run for 30 seconds. More information available at the Cortex Video Trainer Resource. Click Remote Control then Timers Videos.

If statements If statement in the program is evaluated by condition contained in parentheses If condition is true, commands between braces are run If condition is false, those commands are ignored Very similar to how a while loop works, but does not repeat the code

If-else statements If-else statement is an expansion of if statement If checks condition and runs appropriate commands when it evaluates to true Else allows code to run when condition is false Either if or else branch is always run once

References Carnegie Mellon Robotics Academy. (2011). ROBOTC. Retrieved from http://www.robotc.net