# Incremental Loop

This topic is 4381 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

I have several calculations that require a number to loop incrementally until the calculation is satisfied. What is the most simple counter that I can write as a custom function in the form of something like: Counter(Increment) ?

##### Share on other sites

It really depends on the specifics. Custom functions are recursive, not iterative. Most often, you would call the next iteration with some parameter reduced by 1, until it runs out.

##### Share on other sites

I understand. I'd have to make my calculations work recursively. The number that I want to increment is a divisor that just goes from 1 (+1) to whenever the result is true. It's just much easier to think of this calculation iteratively. I'd put it in a script, but that would probably run slower than using a custom function. The calculation is used for every new record and has a lot of dependencies that get updated.

##### Share on other sites

Well, "the most simple counter" would be a parameter named counter, initialized to 1.

a divisor that just goes from 1 (+1) to whenever the result is true.

Not sure what that means - couldn't you use the Mod() function to get the result without recursing?

Edited by comment
##### Share on other sites

Well, "the most simple counter" would be a parameter named counter, initialized to 1.

Not sure what that means - couldn't you use the Mod() function to get the result without recursing?

One of the tests and results in a case() function that I want to apply it to is something like this, where n is the divisor starting from 2, then 3, 4, and so on until it evaluates as true. If there's a remainder, it gets passed on to another calculation field that does something similar, and then a few more times. This is actually part of a slew of calculation fields that deal with remainders of an original input value. Mod() doesn't always give me the proper remainder and that's the first function that I worked with before my idea of using iterative increments.

WSTurnPageSides ≥ PageFit / n ; PageFit / n ;

##### Share on other sites

I believe the condition:

`WSTurnPageSides ≥ PageFit / n `
```

can be rewritten as:

```
`n ≥ PageFit / WSTurnPageSides`
```

and the smallest integer n that will satisfy the condition can be calculated as =

```
`Ceiling ( PageFit / WSTurnPageSides )`

##### Share on other sites

I believe the condition:

`WSTurnPageSides ≥ PageFit / n `
```

can be rewritten as:

```
`n ≥ PageFit / WSTurnPageSides`
```

and the smallest integer n that will satisfy the condition can be calculated as =

```
`Ceiling ( PageFit / WSTurnPageSides )`

That's working very well so far and it reduces a lot of calculations into one simple line. I wrote the condition like this before but missed the Ceiling() function. Thanks again for your help.

##### Share on other sites

This topic is 4381 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account