> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# arc:check

> 检查属性是否存在或计算布尔表达式，仅在满足条件时执行正文块。

export const siteNameShort = "知行之桥";

使用带或不带 **value** 参数的 arc:check 关键字。如果没有 value 参数，则可确保在执行 arc:check 主体之前，属性存在于项目中且不是空字符串。

如果指定 value 参数，则仅当表达式求值为真时，才会执行 arc:check 主体。其他值均视为假。求值不区分大小写。

与 {siteNameShort}Script 中的其他简单条件一样，arc:check 可与 [arc:else](./op-arc-else) 关键字配对使用。

<Note>与 [arc:equals](./op-arc-equals) 不同，`arc:check` 如果对象中不存在该属性，也不会引发异常。</Note>

## 参数

* **item**：要检查的属性的对象。该参数不是必需的，如果没有对象被指定，将会使用默认的输出对象。
* **attr**：要检查的属性的名称，该参数是必需的。
* **value**：计算结果为 `true` 或 `false` 的表达式。例如：格式化器返回 true 或 false 的结果。
* **action**：如果表达式计算为 true，要执行的操作。允许值有：`break`，`continue`。

## 控制属性

无

## 示例

**检查项目是否存在某个属性**

本示例使用 arc:check 来检查 `result` 项目是否存在 `number` 属性。如果为真，则在消息中添加标头。否则，抛出错误。

```xml theme={null}
<arc:set attr="result.number" value="95" />

<!-- Check that the number attribute exists on the result item first. -->
<arc:check attr="result.number">
  <!-- If true, add a header. -->
  <arc:if exp="[result.number | lessthan(100)]">
    <arc:set attr="out.header:numberlessthan100" value="true" />
    <arc:set attr="out.filepath" value="[filepath]" />
    <arc:push item="out" />
    <!-- Else, throw an error. -->
    <arc:else>
      <arc:throw code="HighValue" desc="The target value was above the desired value of 100." />
    </arc:else>
  </arc:if>
</arc:check>
```

**枚举过程中检查值**

本示例枚举范围从 1 到 10，并使用 `arc:check` 检查迭代值。如果迭代值等于 5，则跳出枚举。如果迭代值不等于 5，则创建一个包含数据的文件，并将该文件作为输出推送。

```xml theme={null}
<arc:enum range="1..10">
  <!-- Check the current iteration and break if it is equal to 5. -->
  <arc:check value="[_value | equals(5)]" action="break" />
  <!-- For iterations not equal to 5, create a file and push it as output. -->
  <arc:setm item="out">
    FileName=Result_[_value].txt
    Data=The enumeration value is [_value].
  </arc:setm>
  <arc:push item="out" />
</arc:enum>
```

## 另请参阅

* [arc:exists](./op-arc-exists)：检查属性是否存在。
* [arc:equals](./op-arc-equals)： 检查相等性。
* [arc:notequals](./op-arc-not-equals)：检查不等性。
