mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Make while()
handle break
This commit is contained in:
@ -984,7 +984,7 @@ static const char* const jq_builtins[] = {
|
||||
"def while(cond; update): "
|
||||
" def _while: "
|
||||
" if cond then ., (update | _while) else empty end; "
|
||||
" _while;",
|
||||
" try _while catch if .==\"break\" then empty else . end;",
|
||||
"def limit(n; exp): if n < 0 then exp else foreach exp as $item ([n, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1]) end;",
|
||||
};
|
||||
#undef LIBM_DD
|
||||
|
@ -226,6 +226,10 @@ null
|
||||
1
|
||||
[1,2,4,8,16,32,64]
|
||||
|
||||
[while(.<100; .*2|if . > 10 then break else . end)]
|
||||
1
|
||||
[1,2,4,8]
|
||||
|
||||
[foreach .[] as $item ([3, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1])]
|
||||
[11,22,33,44,55,66,77,88,99]
|
||||
[11,22,33]
|
||||
|
Reference in New Issue
Block a user