> ## 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 主體。其他值均視為假。求值不區分大小寫。

與 ArcScript 中的其他簡單條件一樣，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)：檢查不等性。
