Crystal Reports Designer  

退出 For 循环(Crystal 语法)

使用 Exit For 可以从 For 循环中退出。以下示例在全局数组名称中搜索名称“Fred”。如果找到了该名称,将返回该名称在数组中的索引。否则返回 –1。

例如,如果名称数组是:

["Frank", "Helen", "Fred", "Linda"]

则公式返回 3。

Global StringVar Array names;
//The names array has been initialized and filled
//in other formulas
Local NumberVar i;
Local NumberVar result := -1;
//The UBound function returns the size of its array
//argument
For i := 1 to UBound (names) Do
(
   If names [i] = "Fred" Then
   (
      result := i;
      Exit For
   )
);
result

当被看作是表达式时,For 循环始终返回 True 布尔值。因此,公式将只是显示该值为 True 而不是预期的结果,所以几乎从不愿意让 For 循环作为公式的最后一个表达式。

另请参见

For 循环