0% found this document useful (0 votes)
45 views5 pages

11control Loop

This document discusses different types of loops that can be used in NQC programming including while loops, do-while loops, and until loops. It provides examples of the general syntax for each type of loop and describes how they work. While loops repeat a statement or block of code while a condition is true. Do-while loops always execute the code block at least once before checking the condition. Until loops wait for a condition to become true before continuing to the next statement.

Uploaded by

approachtheprob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views5 pages

11control Loop

This document discusses different types of loops that can be used in NQC programming including while loops, do-while loops, and until loops. It provides examples of the general syntax for each type of loop and describes how they work. While loops repeat a statement or block of code while a condition is true. Do-while loops always execute the code block at least once before checking the condition. Until loops wait for a condition to become true before continuing to the next statement.

Uploaded by

approachtheprob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

NQC: Control Structures: Loops

Last updated 10/5/05


References:
NQC Tutorial
Baum Chapter 3
Baum Appendix D pg 368.

While Control Structure




Sample forms
1) while(Timer(0) <= 10) x+=5;

2) while(z != 5)
{
if(SENSOR_1==0)
{
STATEMENTS EXECTUED IF TRUE
}
else
{
STATEMENTS EXECTUED IF FALSE
}
}
-----------------------------------------------

General Form
while(condition) statement
Creating an Infinite Loop

while(true)
{
until(Timer(0) > TIMER_LIMIT);
PlayTone(440, 10);
ClearTimer(0);
bumps = 0;
}


A Closely Related Cousin to the while

do
{
Toggle(OUT_A);
Off(Out_B);
} while (SENSOR_2 <= 10);

Notice the do while is always executed at least one
time since the test of the condition is at the bottom of
the loop.
General Form
do statement while(condition)
The until control structure
Example
until(SENSOR_2>=5) x+=1;

This is often used to trigger a segment of code when an event
occurs

until(SENSOR_1==1)

Note in the last example the statement is the null statement. The
program acts as though it holds at this point until the event
SENSOR_1==1 occurs and then it is released to the next
statement in the program.
General Form
until(condition) statement

You might also like