November 25, 2024, 12:08:02 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Nesting FOR/NEXT?

Started by steveo, September 09, 2007, 03:06:03 PM

Previous topic - Next topic

steveo

Jonny,
My man, my ace, my brother from another mother!

Forgive such a nebulous question, but if you were to create a for/next loop, then nest another within it, how would you go about it?

JonnyMac

September 09, 2007, 03:36:23 PM #1 Last Edit: September 10, 2007, 01:52:53 PM by JonnyMac
Easy-peezy -- use two control variables.  This little segment, for example, will flash an LED quickly five times and then pause one second, and do that three times.

Main:
  FOR burst = 1 TO 3
    FOR flashes = 1 TO 5
      HIGH Led
      PAUSE 100
      LOW Led
      PAUSE 100     
    NEXT ' (flashes)
    PAUSE 1000
  NEXT ' (burst)


Note how formatting (indenting, etc.) keeps things organized and easy to follow -- I added comments after each NEXT so you know what's what.
Jon McPhalen
EFX-TEK Hollywood Office

steveo