Files
freeCodeCamp/guide/portuguese/csharp/for/index.md
Randell Dawson 0a1eeea424 fix(guide) Replace invalid prism code block names (#35961)
* fix: replace sh with shell

fix replace terminal with shell

fix replace node with js

fix replace output with shell

fix replace cs with csharp

fix replace c++ with cpp

fix replace c# with csharp

fix replace javasctipt with js

fix replace syntax  with js

fix replace unix with shell

fix replace linux with shell

fix replace java 8 with java

fix replace swift4 with swift

fix replace react.js with jsx

fix replace javascriot with js

fix replace javacsript with js

fix replace c++ -  with cpp

fix: corrected various typos

fix: replace Algorithm with nothing

fix: replace xaml with xml

fix: replace solidity with nothing

fix: replace c++ with cpp

fix: replace txt with shell

fix: replace code with json and css

fix: replace console with shell
2019-05-15 19:08:19 +02:00

47 lines
1.3 KiB
Markdown

---
title: For Loop
localeTitle: Para loop
---
# Para loop
O loop `for` executa um bloco de código até que uma condição especificada seja falsa. Embora um `for` circuito parece um [`while` ciclo](https://guide.freecodecamp.org/csharp/while-loop) , os desenvolvedores devem usá-los **corretamente.** Use `while` laços quando o número de iterações são variáveis, de outro modo utilizar `for` lacetes. Um uso comum de loops `for` são iterações de array. 1
## Sintaxe
```csharp
for ((Initial variable); (condition); (step))
{
(code)
}
```
O loop C # for consiste em três expressões e algum código.
## Descrição
* _Variável inicial_ : seu estado inicial, por exemplo, int i = 0;
* _Condição_ : Enquanto esta condição for verdadeira, o código continuará a ser executado, por exemplo, i <= 5;
* _Etapa_ : O incremento ou decremento da variável inicial, por exemplo, i ++ ou i- = 2.
## Exemplo
```csharp
int[] array = { 1, 2, 3, 4, 5 };
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine("Item on index {0} is {1}", i, array[i]);
}
```
## Saída:
```
> Item on index 0 is 1
> Item on index 1 is 2
> Item on index 2 is 3
> Item on index 3 is 4
> Item on index 4 is 5
```
### Fontes
1 https://docs.microsoft.com/pt-br/dotnet/csharp/language-reference/keywords/for