# how does vector \\\[1\] work?

**URL:** <https://forum.kx.com/t/how-does-vector-1-work/8328>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [August 12, 2013, 2:35am UTC](https://forum.kx.com/t/how-does-vector-1-work/8328 "2013-08-12T02:35:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhakar1](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sudhakar1](https://forum.kx.com/u/sudhakar1)\
**Post date:** [August 12, 2013, 2:35am UTC](https://forum.kx.com/t/how-does-vector-1-work/8328/1 "2013-08-12T02:35:00Z")

</div>

can some one please explain how scan works, when the left arg is a vector and the right arg is either atom or vector?

tia.

q)0 3 6 2 5 1 4[1] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; / / from idiom # 1005 of qidioms

1 3 2 6 4 5

)q 5 2 0 [1]

1 2 0 5 0N

q)4 6 1[1 2 3]

1 2 3

6 1 &nbsp;

&nbsp; 6 &nbsp;

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [August 12, 2013, 5:46am UTC](https://forum.kx.com/t/how-does-vector-1-work/8328/2 "2013-08-12T05:46:00Z")

</div>

Just imagine the verb being indexing (@)

Cheers,  
? Attila

---

<div class="post-metadata">

**Author:** ![WooiKent\_Lee](https://avatars.discourse-cdn.com/v4/letter/w/5f8ce5/32.png) [@WooiKent\_Lee](https://forum.kx.com/u/WooiKent_Lee)\
**Post date:** [August 12, 2013, 9:30am UTC](https://forum.kx.com/t/how-does-vector-1-work/8328/3 "2013-08-12T09:30:00Z")

</div>

so "" is used as iteration in this case, and as Attila said, the verb is indexing

iteration returns result as:  
x,f(x),f(f(x)),f(f(f(x))),…

http://code.kx.com/wiki/Reference/BackSlash

so to explain the first question:

q)0 3 6 2 5 1 4[1]

1 3 2 6 4 5

the first result is 1, so return 1

use the first result and index ( (0 3 6 2 5 1 4)[1] ) which return 3

use the second result and index ( (0 3 6 2 5 1 4)[3] ) which return 2

use the third result and index ( (0 3 6 2 5 1 4)[2] ) which return 6

use the fourth result and index ( (0 3 6 2 5 1 4)[6] ) which return 4

use the fifth result and index ( (0 3 6 2 5 1 4)[4] ) which return 5

the result stops here because if you use the sixth result and index ( (0 3 6 2 5 1 4)[5] ) which return 1, the result (1 3 2 6 4 5) will just keep repeating itself indefinitely

so the best result q can return is 1 3 2 6 4 5 in the end…

if you use this logic on second and third question, it will be clearer

---

<div class="post-metadata">

**Author:** ![sudhakar1](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sudhakar1](https://forum.kx.com/u/sudhakar1)\
**Post date:** [August 12, 2013, 2:56pm UTC](https://forum.kx.com/t/how-does-vector-1-work/8328/4 "2013-08-12T14:56:00Z")

</div>

Thank you all, really appreciate it. Next time, I will read the documentation first.
