如果条件为False,则Haskell迭代

如果条件为False,则Haskell迭代,haskell,Haskell,我有一组数字。例如set=[1,3,4,5,6,7,8]。我需要编写一个循环,它只选择总数小于max=30的元素 for(int i = 0;i<set.length();i++) { total = total + set[i]; if (total <= max) return i; } ..... elements are from 0 to returned index for(int i=0;i沿着列表走,发射元素,直到它们的总数太大。因此: thePriceIsRigh

我有一组数字。例如
set=[1,3,4,5,6,7,8]
。我需要编写一个循环,它只选择总数小于
max=30的元素

for(int i = 0;i<set.length();i++) { total = total + set[i]; if (total <= max) return i; }
.....
elements are from 0 to returned index

for(int i=0;i沿着列表走,发射元素,直到它们的总数太大。因此:

thePriceIsRight max (x:xs) | x <= max = x : thePriceIsRight (max-x) xs
thePriceIsRight _ _ = []

沿着列表往下走,发射元素,直到它们的总数太大。因此:

thePriceIsRight max (x:xs) | x <= max = x : thePriceIsRight (max-x) xs
thePriceIsRight _ _ = []

“只有一个周期”是什么意思?如果你是指对列表的一次遍历,那么如果你利用懒惰,你确定这是必要的吗?什么是“只有一个周期”意思?如果你指的是单次遍历列表,你确定如果你利用了惰性,这是必要的吗?这对
scanl
更好,不是吗?
priceisright max=takeWhile(这对
scanl
更好,不是吗?
priceisright max=takeWhile(