> For the complete documentation index, see [llms.txt](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/7.-expressoes-de-atribuicao/escreva-atribuicoes-em-instrucoes-separadas.md).

# Escreva Atribuições em Instruções Separadas

É frequentemente conveniente escrever uma atribuição dentro de uma condição `if`, mas isso pode reduzir a legibilidade do programa. Aqui está um exemplo do que evitar:

```c
if (x = advance (x))
  …
```

A ideia aqui é avançar `x` e testar se o valor é diferente de zero. No entanto, os leitores podem não perceber que está sendo usado ‘=’ e não ‘==’. De fato, escrever ‘=’ onde ‘==’ era pretendido dentro de uma condição é um erro comum, por isso o GNU C pode emitir avisos quando ‘=’ aparece de uma forma que sugere ser um erro.

É muito mais claro escrever a atribuição como uma instrução separada, assim:

```c
x = advance (x);
if (x != 0)
  …
```

Isso torna inconfundivelmente claro que `x` está recebendo um novo valor.

Outro método é usar o operador vírgula (veja [Operador Vírgula](#user-content-fn-1)[^1]), assim:

```c
if (x = advance (x), x != 0)
  …
```

No entanto, colocar a atribuição em uma instrução separada geralmente é mais claro, a menos que a atribuição seja muito curta, pois isso reduz o aninhamento.

{% embed url="<https://www.youtube.com/watch?v=kj6Y5EkioIw>" %}

[^1]: Capítulo pendente de tradução


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://mentebinaria.gitbook.io/manual-da-linguagem-gnu-c/7.-expressoes-de-atribuicao/escreva-atribuicoes-em-instrucoes-separadas.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
