Skip to main content

VEX IQ - Loops - Code Challenge

Objective

The next challenge will be having the robot loop around without stopping at the end. This part of program will introduce looping or the “forever” block to keep the robot in motion.  The “forever” block should include the any block of code that you want to happen forever. 

Essential Keywords

Loops - 

Routines- 

 

1.  Attention (5 Min.)

 

2. Learners Guidance 

The point of this project is to create a loop where the robot continues to do the same thing over and over again and learning how to set up and use a forever block. 

This introduces a new set of blocks to them called “control”. In the control blocks palette there are other blocks of code that help you repeat code forever, for a certain number of times, while a condition is true or many other blocks of code that help to control your code. 

control blocks vexcode iq

Sample code 

sample loop code vexcode iq    sample loop code vexcode iq

Lastly we could increase the speed of our robot driving and turning so the loops go through the routines a bit quicker. Especially if your robot is doing long distances. However this comes at the price of losing some accuracy. While the robot is moving faster it might have a harder time coming to a stop when its task is finished. if the "set drive velocity" or "set turn velocity" are set at the beginning of the code then the rest of the code will run at that speed and it does not need to be in the forever loop.

Sample Code

set speed vexcode iq

3.  Explore (25 - 30 Min.)

Try programming your robot to move in a square shape. 

How many degrees does your robot need to turn to create a square using your robot? 

Try using a "repeat" loop to create your square. How many times does your robot need to repeat a sequence to create the square shape? 

5. Closure (Min.)

Repetition of code are called loops, and they are defined as statements that execute lines of code (or routines) repeatedly according to conditions or iterations. While the code repeats itself, it is performing an action that must terminate when a condition is met or when an iteration stops.

6. Evaluate

Essential Questions

What kinds of programming loops did you use in this project? 

Why are loops necessary in code? 

Can you think of a routine that you program in your life to happen over and over?