XQuery 是否有 FLWOR 表达式的退出语句

发布于 2024-09-07 03:15:47 字数 90 浏览 2 评论 0原文

我想知道 xquery FLWOR 表达式是否有像 continue 和 break 这样的退出语句?

例如,我想在达到特定条件时退出 for 循环。

I would like to know if xquery FLWOR expression has an exit statement like continue and break?

For example I want to exit the for loop when a particular condition is reach.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ま昔日黯然 2024-09-14 03:15:47

我想知道 xquery FLWOR 是否有效
表达式有一个退出语句,例如
继续和中断?

例如我想退出 for
当特定条件满足时循环
达到。

XQuery 是一种函数语言,这意味着不存在严格的执行顺序概念。因此,当某些事情发生时,任何尝试做特定事情的尝试都是没有意义的。

正确的方法是在满足特定条件的情况下执行某些操作。

除了使用 < 之外,无法退出 FLWOR 表达式code>error() 函数,但这会终止处理。

人们不应该太担心优化——许多处理器都有很好的优化器。

因此,许多处理器将延迟求值,并在第一次产生满足 special-condition() 的结果时停止对下面的 FLOWR 表达式的求值:

  (someFlowerExpression )[specific-condition(.)][1]

I would like to know if xquery FLWOR
expression has an exit statement like
continue and break?

For example I want to exit the for
loop when a particular condition is
reach.

XQuery is a functional language, which among many other things means that there is no strict concept of order of execution. Therefore any attempts to do something specific when something happens, are not meaningful.

The correct approach is to do something if a specific condition is satisfied.

There is no way to exit a FLWOR expression, other than using the error() function, but this terminates processing.

One shouldn't worry too much about optimization -- many processors have good optimizers.

Thus many processors will evaluate lazily and will stop the evaluation of the FLOWR expression below, the first time it produces result that satisfies the specific-condition():

  (someFlowerExpression )[specific-condition(.)][1]
夏の忆 2024-09-14 03:15:47

XQuery Scripting 有一个退出语句:

variable $i := 0;
while(true())
{
  $i := $i + 1;
  if($i = 3) then
      exit returning $i 
  else();
} 

或者

for $i in (1 to 1000)
return
  if($i = 3) then
    exit returning $i;
  else();

您可以在 http://www.zorba-xquery.com/html/demo#JvSLsVh3ZjhvTHecVd9jyE1vEBc=

XQuery Scripting has an exit statement:

variable $i := 0;
while(true())
{
  $i := $i + 1;
  if($i = 3) then
      exit returning $i 
  else();
} 

Or

for $i in (1 to 1000)
return
  if($i = 3) then
    exit returning $i;
  else();

You can try this example live at http://www.zorba-xquery.com/html/demo#JvSLsVh3ZjhvTHecVd9jyE1vEBc=

贵在坚持 2024-09-14 03:15:47

虽然这个问题很老了,但我回答它是因为一些新人可能会遇到这种情况并会得到更好的解决方案。

该解决方案可以在 BaseX 7.6 上轻松运行,

for $i in (1 to 10)
return
   if ($i = 3) then
       $i
   else 
       exit

输出将为 - 3

或这将生成输出 - 3,

for $i in (1 to 10)
return
   if ($i = 3) then
       $i
   else 
       ()

Though the question is quite old, I am answering it as some new people might face such situation and would get a better solution.

This solution would run easily on BaseX 7.6

for $i in (1 to 10)
return
   if ($i = 3) then
       $i
   else 
       exit

Output will be - 3

OR this will generate the output - 3,

for $i in (1 to 10)
return
   if ($i = 3) then
       $i
   else 
       ()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文