Files
freeCodeCamp/guide/spanish/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: En bucle
---
# En bucle
El bucle `for` ejecuta un bloque de código hasta que una condición especificada es falsa. Aunque una `for` bucle se parece a un [`while` de bucle](https://guide.freecodecamp.org/csharp/while-loop) , los desarrolladores deben utilizar de manera **adecuada.** Use `while` bucles cuando el número de iteraciones es variable, de lo contrario use `for` bucles. Un uso común de `for` bucles son iteraciones de matriz. 1
## Sintaxis
```csharp
for ((Initial variable); (condition); (step))
{
(code)
}
```
El C # para el bucle consta de tres expresiones y algunos códigos.
## Descripción
* _Variable inicial_ : su estado de inicio, por ejemplo, int i = 0;
* _Condición_ : Mientras esta condición sea verdadera, el código continuará ejecutándose, por ejemplo, i <= 5;
* _Paso_ : El incremento o decremento de la variable inicial, por ejemplo, i ++ o i- = 2.
## Ejemplo
```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]);
}
```
## Salida:
```
> 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
```
### Fuentes
1 https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/for