Link to home
Start Free TrialLog in
Avatar of zipnotic
zipnoticFlag for United States of America

asked on

For Next Loop on compass degrees

Hello,

Trying to build this:
For A = startAzimuth to endAzimuth mod 360 step 10
      'Do stuff
Next

But it obviously fails when the start azimuth is less than 360 and end azimuth crosses 360/0.  How can I step through compass directions?

A clearer example:

For A = 335 to 25 step 10 mod 360

next A

I believe there was a simple way but I can't find it now.

Thanks!
Avatar of kaufmed
kaufmed
Flag of United States of America image

How about?

For A = startAzimuth to IF(endAzimuth < 360, endAzimuth, endAzimuth mod 360) step 10
...

Open in new window

Avatar of zipnotic

ASKER

It skipped over the loop with:
For A = 345 to IF(105<360, 105, 105 mod 360) step 10

next a
Ok, but 105 is less than 345, so how were you expecting that to work? The initializer, 345 in this case, needs to be smaller than the condition, 105 in your example.
ASKER CERTIFIED SOLUTION
Avatar of zipnotic
zipnotic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this is intended to always run counterclockwise, right?
If so, I would increase the endAzimuth by 360 until it is same or greater than startAzimuth, using a While loop.
After that, you can use the For loop with confidence.
Figured it out.