# iterate question

**URL:** https://forum.kx.com/t/iterate-question/10380
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [September 13, 2015, 11:57pm UTC](https://forum.kx.com/t/iterate-question/10380 "2015-09-13T23:57:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)
#### Post date: [September 13, 2015, 11:57pm UTC](https://forum.kx.com/t/iterate-question/10380/1 "2015-09-13T23:57:00Z")

</div>

Question is on the highlighted statement below:

1. Does the argument (like the scan operation) become the previous output of the command i.e. the orange highlight becomes the parameter to f to yield the blue highlight ?

2. In the same output mentioned in q1 above, does the program stop because machine because of 2 reasons:

&nbsp; &nbsp; &nbsp;1. 1e-256 squared leads a 0

&nbsp; &nbsp; &nbsp;2. two 0s are not printed because it would violate the rule in violet below

1. Please confirm : "value matching the argument" is a subset of the "last seen is produced" clause , because "next value" is the " function applied to the previous value" &nbsp;and hence "previous value" is the argument for the "next value". Better explained in question 4 below.

2. In the yellow highlight below, it does not mention that the first output will be the argument itself

## iterate

If f is a&nbsp; **monadic** &nbsp;function, f\ calls f on its argument repeatedly until a value matching the argument or the last seen is produced. The result is the argument followed by all the results except the last. For example:

```
q)(neg\)11 -1q)(rotate[1]\)"abcd"("abcd";"bcda";"cdab";"dabc")q)({x\*x}\)0.10.1 0.01 0.0001 1e-08 1e-16 1e-32 1e-64 1e-128 1e-256 0q){x\*x}\[0.1] / alternate syntax0.1 0.01 0.0001 1e-08 1e-16 1e-32 1e-64 1e-128 1e-256 0

```

W

---

<div class="post-metadata">

### Author: ![LamHinYan](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@LamHinYan](https://forum.kx.com/u/LamHinYan)
#### Post date: [September 14, 2015, 8:22am UTC](https://forum.kx.com/t/iterate-question/10380/2 "2015-09-14T08:22:00Z")

</div>

A4.&nbsp;If f is a&nbsp; **monadic** &nbsp;function, f\ calls f on its argument repeatedly until a value matching the argument or the last seen is produced. The result **is the argument** followed by all the results except the last.

q){mod[x+1; 3]}[0] / stops when it cycles back to zero (the argument)

0 1 2

q){x+1}\[0] / monotonically increasing sequence that goes OOM

wsfull

![]()

---

<div class="post-metadata">

### Author: ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)
#### Post date: [September 14, 2015, 1:22pm UTC](https://forum.kx.com/t/iterate-question/10380/3 "2015-09-14T13:22:00Z")

</div>

Yan Yan, you are the best :-) . Thanks for the excel explanation.

Regarding the argument being in the result question. My initial question was maybe not clear and in-fact its not really a question, but more of a comment. If you see below (I feel), the two highlights contradict each other. If you go by the first sentence, you will not arrive at the second highlight conclusion logically (or maybe I cant even see the logic). A moot point… if anyone cares to answer.
