Presentation is loading. Please wait.

Presentation is loading. Please wait.

NQC: Control Structures: Loops Last updated 10/5/05 References: NQC Tutorial Baum Chapter 3 Baum Appendix D pg 368.

Similar presentations


Presentation on theme: "NQC: Control Structures: Loops Last updated 10/5/05 References: NQC Tutorial Baum Chapter 3 Baum Appendix D pg 368."— Presentation transcript:

1 NQC: Control Structures: Loops Last updated 10/5/05 References: NQC Tutorial Baum Chapter 3 Baum Appendix D pg 368.

2 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 General Form while(condition) statement

3 Creating an Infinite Loop while(true) { until(Timer(0) > TIMER_LIMIT); PlayTone(440, 10); ClearTimer(0); bumps = 0; }

4 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) General Form do statement while(condition)

5 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 realeased to the next statement in the program. General Form until(condition) statement General Form until(condition) statement


Download ppt "NQC: Control Structures: Loops Last updated 10/5/05 References: NQC Tutorial Baum Chapter 3 Baum Appendix D pg 368."

Similar presentations


Ads by Google