# Function

Function 的概念是把重複的東西組起來變成一個功能。這樣可以透過Function名直接執行動作。以一個名字取代一串程式碼也可以使程式變得好讀。

宣告

```cpp
// <return type> <function name> (<parameters>)
int do_something(int number) {
    return number; // return value
}
```

用途範例

<pre class="language-cpp"><code class="lang-cpp">void arcade_drive(int forward, int rotation) {
<strong>    left_motor.moveVelocity(forward + rotation);
</strong><strong>    right_motor.moveVelocity(forward - rotation);
</strong><strong>}
</strong></code></pre>

```cpp
void opcontrol() {
	Controller master(ControllerId::master);
	Motor left_motor(1);
	Motor right_motor(-2);

	while (true) {
		arcade_drive(master.getAnalog(ControllerAnalog::leftY), master.getAnalog(ControllerAnalog::rightX));
		pros::delay(10);
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://acezxn.gitbook.io/vex-ji-qi-ren-cheng-shi-jiao-xue/ji-chu-jiao-xue/mo-zu-hua/function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
