Repeating Workcell Actions with for Loops
Using loops to repeat predictable manufacturing actions.
Your lesson guide
Objective
Write a for loop with range() Use a loop counter Replace repeated code with a loop
Materials
For the online work: a browser and your engineering notebook. Follow the activity’s materials list for any physical build, and get teacher approval before using equipment.
Plan your time
Suggested work block: 45–60 minutes. Physical builds and projects may span several classes; follow your teacher’s schedule.
How to Use This Page
Python Idea + Workcell Connection
A for loop repeats a block of code a known number of times. range(3) produces the values 0, 1, and 2, so the loop runs three times.
The loop body must be indented. Every indented command is repeated once per loop cycle.
For loops are useful when the Workcell must repeat a known number of identical production cycles.
Trace This Code
Read every line and predict what the program would do before opening the practice check.
for part_number in range(3):
print("Processing part", part_number + 1)
arm.move_to(100, 150, 120)
arm.move_to(100, 150, 45)
arm.set_end_effector_magnet(True)
arm.move_to(100, 150, 120)Check Your Understanding
Rule: If you missed more than one question, reread Learn It and trace the example again before continuing.
Trace the Code
How many times does the pickup sequence run? What values does part_number take?
Do first: Write your answer in your engineering notebook.
Reveal Self-Check
The pickup sequence runs three times. part_number takes the values 0, 1, and 2.
Debug the Program
Find and correct every error before opening the answer.
for part_number in range(3)
print("Processing part")
arm.move_to(100, 150, 120)Reveal Debugging Check
Add a colon after range(3) and indent the print statement to match the other loop-body command.
Change Working Code
Change the loop so five parts are processed and the displayed part number starts at 1.
Success Check
Evidence: Paste the revised code into your engineering notebook.
Build It Yourself
Write a for loop that repeats a simple pick-and-place sequence four times.
Before You Finish
Python Practice Lab
Edit the code, predict the output, then click Run Code. No physical Workcell is connected.
P.6 Practice
Predict what the code will do, then click Run Code.
Tip: Press Ctrl+Enter (Cmd+Enter on Mac) to run. The mock arm object prints simulated Workcell actions instead of controlling hardware.
Explain Your Code
Without looking back at Learn It, answer these in your notebook:
What a Strong Response Includes
A strong response names the Python idea accurately, connects it to a specific Workcell action or decision, and identifies a realistic syntax or logic error from this lesson.
Ready for the Next Lesson?
Move on only when you can check every statement. If one is still uncertain, revisit the worked example or redo Fix It before continuing.
VEX Workcell Python API
Use the official VEX API only as a programming reference to verify method names and parameters. The examples use the configured arm name arm. No physical Workcell is required.
Build your lesson report
Checkpoint: is your evidence ready?
- Check calculations, units, labels, and measurements against the activity requirements.
- Record what actually happened, including unexpected results.
- Explain what you changed and why; attach required drawings, photos, CAD, or code in your classroom assignment.
Submit the evidence specified in the activity and your classroom assignment. The report below collects your notes, calculations, observations, and reflections; attach any required drawings, photos, CAD, or code separately.
A PDF download is not a submission. Review it, then upload it and any required attachments through your classroom assignment system.
