Introduction to Robotics/Control Flow/Lecture/Teachers: Difference between revisions
wikademia>Whiteknight New page: {{Introduction to Robotics/Nav|Control Flow}} == Control Flow == A computer can only perform one instruction at a time. In a program, we write the instructions that we want the computer ... |
wikademia>Dr. Eme m moved Beta:Introduction to Robotics/Control Flow/Lecture/Teachers to Introduction to Robotics/Control Flow/Lecture/Teachers over redirect |
||
| (8 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{ntnes}} | ||
== Control Flow == | == Control Flow == | ||
| Line 9: | Line 9: | ||
We have already seen the FOR / NEXT loop in the previous lab, but what does it do? A FOR / NEXT loop uses a counter variable to count the number of loops. Each time we perform the loop, we increase the value of the counter variable. The NEXT keyword moves the control flow back to the top of the loop. If your loop does not have a NEXT keyword, it will not repeat. Once the counter variable reaches the TO value, the loop exits, and the control flow continues after the loop. | We have already seen the FOR / NEXT loop in the previous lab, but what does it do? A FOR / NEXT loop uses a counter variable to count the number of loops. Each time we perform the loop, we increase the value of the counter variable. The NEXT keyword moves the control flow back to the top of the loop. If your loop does not have a NEXT keyword, it will not repeat. Once the counter variable reaches the TO value, the loop exits, and the control flow continues after the loop. | ||
{{Introduction to Robotics/Visual| | {{Introduction to Robotics/Visual|FOR NEXT 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. | 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| | {{Introduction to Robotics/Visual|Nested Loops 1}} | ||
}} | |||
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| | {{Introduction to Robotics/Visual|Nested Loops}} | ||
}} | |||
=== 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| | {{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}} | ||
}} | |||
== Branches == | == Branches == | ||