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.

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.
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
CS0004: Introduction to Programming Repetition – Do Loops.
Automation and Robotics
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.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Introduction to Sensors
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Four Fundamental Pieces Instruction Control Structure Function Expression.
Programming Design ROBOTC Software Principles of Engineering
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Algorithms: Branching and Iteration (in Scratch)
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Mindstorm NXT-G Introduction Towson University Robotics.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
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!
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
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.
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?
Movement using Shaft Encoders
Using Encoders to go Straight
Variables and Functions
When I want to execute the subroutine I just give the command Write()
IF if (condition) { Process… }
While Loops and If-Else Structures
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Auto Straightening using VEX Shaft Encoders
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
RobotC While loop When and how to use the while loop
if-else Structures Principles of Engineering
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
While Loops And If-Else Structures
How to allow the program to know when to stop a loop.
Presentation transcript:

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 condition remains true Three main parts to every while loop

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 every time loop repeats before commands between curly braces are 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

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

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 –Becareful where you clear timers

Timers Timer T1 is used as the condition for the while loop, which will run for 30 seconds

If Statements If statement in the program is evaluated by condition contained in parenthesis –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

Multiple If-Else Statements Be careful when using two separate if-else statements, particularly if both are used to control the same mechanism One branch of each if-else statement is always run so that you may create a scenario where the two statements ‘fight’ one another

Multiple If-Else Statements In this example, if one of the touch sensors is pressed, the rightMotor will be turned on in one if-else statement and immediately turned off in the other

Multiple If-Else Statements This can be corrected by embedding the second if-else within the else branch of the first, so that it only runs if the first condition is false

If-Else Shorthand An embedded if-else can also be represented as an else-if

References Carnegie Mellon Robotics Academy. (2011). ROBOTC. Retrieved from