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.

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

ROBOTC for CORTEX While Loops Part 1
While Loops and If-Else Structures
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.
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
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.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
The switch Statement, DecimalFormat, and Introduction to Looping
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
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.
ROBOTC for VEX On-Site Professional Development
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
AUTOMATION WITH ROBOTC Starting to write and troubleshoot computer code.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
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.
Automated Mechanisms Help. Potentiometers Potentiometer Check –Analog Port 2 How they work –Analog sensor –Measures rotation of a shaft between 0 and.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
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!
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.
CHAPTER 4 DECISIONS & LOOPS
REPETITION CONTROL STRUCTURE
Repetition Structures Chapter 9
ROBOTC for VEX Online Professional Development
The switch Statement, and Introduction to Looping
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?
CiS 260: App Dev I Chapter 4: Control Structures II.
Expressions and Control Flow in JavaScript
Movement using Shaft Encoders
Programming – Touch Sensors
The 3-Way Light Switch and The If-And-Only-If Statement
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Loop Control Structure.
Automation and Robotics
While Loops and If-Else Structures
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
While Loops and If-Else Structures
Three Special Structures – Case, Do While, and Do Until
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
Automation with RobotC
Robotics Programming Using Shaft Encoders
Robotics Programming Using Shaft Encoders
A LESSON IN LOOPING What is a loop?
Section 3.7 Switching Circuits
While Loops and If-Else Structures
Introduction to Repetition
Automation with RobotC
Robotics Programming Using Shaft Encoders
Introduction to Repetition
© A+ Computer Science -
Selections and Loops By Sarah, Melody, Teresa.
While Loops and If-Else Structures
While Loops And If-Else Structures
Controlling Program Flow
Presentation transcript:

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 long as a certain condition remains true. There are three main parts to every while loop.

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

2. The Condition The condition controls how long or how many times a while loop repeats. While the condition is true, the while loop repeats; when the condition is false, the while loop ends and the robot moves on in the program. The condition is checked every time the loop repeats, before the commands between the curly braces are run.

3. Commands to be Repeated Commands placed between the curly braces will repeat while the (condition) is true when the program checks at the beginning of each pass through the loop.

The Truth About while() Loops

1. while() Loops do NOT Constantly Check Their Conditions while() loops check their conditions before running the body of code. After the body of code is run, the while() loop checks the condition again. The condition is NOT checked while the body of code is being run.

2. while() Loops do NOT Keep Programs Running Forever Exception: Infinite while() loops Once the while() loop’s condition is met/false, the robot moves past the while loop in the program and does not revisit it. Students often assume that because there is a while() loop in the code, the program keeps on running.

3. while() Loops Are a Programming Structure, not a Command They do not get a semicolon (;) after the condition. Adding a semicolon will cause the while() loop to constantly check the condition without running the body of code.

4. All “until” Commands in the NL Are Actually while() Loops All commands are just a while() loop with a wait command, designed to hold the program flow at that spot in the code.

Boolean Logic Decisions made by robots must always be based on questions which have only two possible answers: yes or no, true or false. Statements that can be only true or false are called Boolean statements, and their true-or-false value is called a truth value.

Boolean Logic

Boolean Logic: Multiple Conditions

Logical Operators Logical Operators allow you to combine two or more full conditions.

Logical Operators: OR When using the Logical OR Operator (II), the entire condition is true if any or all of the individual conditions are true.

Logical Operators: AND When using the Logical AND Operator (&&), the entire condition is true only when all of the individual conditions are true.

While Loop Exercise 1 Example: Program the green LED to repeatedly turn on for 2 seconds, then off for 2 seconds while the limit switch isn’t pressed. Individual: Expand the previous program to loop only while the potentiometer reads less than 2048.

Timers More loop control please? –Question: Where would the wait statement go if we wanted the loop to repeat for a controlled amount of time? –Answer: Nowhere! We need something else. Solution: Timers –Can be thought of as internal stopwatches (4 available). –Timers should be “cleared” anytime before they are used. Watch where you clear them!

Timers In the program below, timer T1 is used as the condition for the while loop, which will run for 30 seconds:

While Loop Exercise 2 Program the green LED to repeatedly turn on for 2 seconds, then off for 2 seconds, while less than 20 seconds have elapsed. Program the green LED to repeatedly turn on for 2 seconds, then off for 2 seconds, forever.