Introduction to Robotics/Control Flow/Lecture/Teachers: Difference between revisions

wikademia>Whiteknight
wikademia>Dr. Eme
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Introduction to Robotics/Nav|Control Flow}}
{{ntnes}}


== Control Flow ==
== Control Flow ==
Line 13: Line 13:
We can “nest” FOR / NEXT loops. “nesting” means that we put one loop inside another loop. When we nest FOR / NEXT loops, we need to use different counter-variables for each loop.
We can “nest” FOR / NEXT loops. “nesting” means that we put one loop inside another loop. When we nest FOR / NEXT loops, we need to use different counter-variables for each loop.


{{Introduction to Robotics/Visual|text=
{{Introduction to Robotics/Visual|Nested Loops 1}}
MyCount1 VAR Byte
MyCount2 VAR Byte
FOR MyCount1 = 0 TO 200
FOR MyCount2 = 0 TO 200
...
NEXT
NEXT
}}


If we use the same counter-variable, the variable will be changing in the inner loop, and the outer loop will not work correctly:
If we use the same counter-variable, the variable will be changing in the inner loop, and the outer loop will not work correctly:


{{Introduction to Robotics/Visual|text=
{{Introduction to Robotics/Visual|Nested Loops}}
MyCount VAR Byte
FOR MyCount = 0 TO 200
FOR MyCount = 0 TO 50
...
NEXT
NEXT
MyCount never reaches 200
}}


=== How it Works ===
=== How it Works ===
Line 48: Line 29:
#If the counter variable is not equal to the TO value, go to #2
#If the counter variable is not equal to the TO value, go to #2


{{Introduction to Robotics/Visual|image=[Insert Image of how a loop works here]|caption=How a FOR / NEXT Loop Works.}}
{{Introduction to Robotics/Visual|FOR NEXT Control Flow}}


== Labels and GOTO ==
== Labels and GOTO ==
Line 54: Line 35:
Labels are like destination points. When we put a label in our code, we can jump to it using a GOTO statement.  
Labels are like destination points. When we put a label in our code, we can jump to it using a GOTO statement.  


{{Introduction to Robotics/Visual|
{{Introduction to Robotics/Visual|Labels and GOTO}}
[Insert an image here
}}


== Branches ==
== Branches ==