---
title: "Bucles"
content_type: tutorial
url: "https://learn.unity.com/tutorial/bucles-xu?language=es"
language: es
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es&version=4.x"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/loops-z2b.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/bucles-xu.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/rupuwen-b.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/rupeu-eap.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/xun-huan.md?language=zh-cn"
last_updated: "2026-08-04T14:21:23.000Z"
---

# Bucles

Aprende a usar los bucles For, While, Do-While y For Each en C# para repetir acciones de forma eficiente en tu código.

How to use the For, While, Do-While, and For Each Loops to repeat actions in code.

Aprende a cómo usar los bucles For, While, Do-While, y For Each para repetir acciones dentro de tu código.

 Este tutorial está incluido en el proyecto [_Scripting_ para principiantes. ](https://learn.unity.com/project/scripting-para-principiantes?language=es&publish=true)

Previo: Sentencias condicionales IF

Siguiente: Modificadores de ámbito y de acceso

## 1. Bucles

[Video](http://www.youtube.com/watch?v=Jefkb3Gm7vE)

## **ForLoop**

```csharp
using UnityEngine;
using System.Collections;

public class ForLoop : MonoBehaviour
{
    int numEnemies = 3;
    
    
    void Start ()
    {
        for(int i = 0; i < numEnemies; i++)
        {
            Debug.Log("Creating enemy number: " + i);
        }
    }
}
```

## **WhileLoop**

```csharp
using UnityEngine;
using System.Collections;

public class WhileLoop : MonoBehaviour
{
    int cupsInTheSink = 4;
    
    
    void Start ()
    {
        while(cupsInTheSink > 0)
        {
            Debug.Log ("I've washed a cup!");
            cupsInTheSink--;
        }
    }
}
```

## **DoWhileLoop**

```csharp
using UnityEngine;
using System.Collections;

public class DoWhileLoop : MonoBehaviour 
{
    void Start()
    {
        bool shouldContinue = false;
        
        do
        {
            print ("Hello World");
            
        }while(shouldContinue == true);
    }
}
```

## **ForeachLoop**

```csharp
using UnityEngine;
using System.Collections;

public class ForeachLoop : MonoBehaviour 
{   
    void Start () 
    {
        string[] strings = new string[3];
        
        strings[0] = "First string";
        strings[1] = "Second string";
        strings[2] = "Third string";
        
        foreach(string item in strings)
        {
            print (item);
        }
    }
}
```
