Jump to content

Recommended Posts

Posted

If I'm in a for...next loop that goes up to 50 Is it possible to make it do something specific every 5th loop without doing if "$i=x or" for all the 5th integers?

  • Moderators
Posted

Champak,

Use the Mod function as a filter: ;)

For $i = 1 To 50
    If Mod($i, 5) = 0 Then ConsoleWrite($i & @CRLF)
Next
That will fire on 5, 10, 15, etc. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

That only fires 'every 5th loop' if you start at 1  (unless of course you account for the starting number and subtract/add that to $i in the mod function, which still seems the long way around).

How is evaluating the variable then doing divsion, a better solution then just counting to 5 yourself inside the loop (or using step)?  Not being coy, just really want to know why this method is being sought in case it is useful.

Edited by boththose

  Reveal hidden contents

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...