kdb/Q 如何迭代函数 x 次?

问题描述 投票:0回答:1

我是 kdb/Q 的新手,迭代相当于什么,我需要运行一个函数 10 次?

在 Python 中,这就像创建某种迭代器,使用 while 循环运行该函数并向迭代器加 1,并在迭代器达到 10 时停止。

for-loop while-loop iterator iteration kdb
1个回答
0
投票

本机方法是按照以下方式使用accumulators/iterators/over/scan:https://code.kx.com/q/ref/accumulators/#do

q){x+1}/[10;1000]
1010
q)
q){x+1}\[10;1000]
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010

例如运行

{x+1}
10 次,起始值为 1000

还有一个

do
关键字,可用于执行 N 次操作,而无需携带下一次运行的输出:https://code.kx.com/q/ref/do/

© www.soinside.com 2019 - 2024. All rights reserved.