How to code in Unity with C# – 05 – while loop

Hi, This is fourth video on “How to code in unity with C#” series. I will explain you how while loop works in C# and how to use it in unity.

CODE:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TutorialFive : MonoBehaviour
{
    public int loops;
    

    // Start is called before the first frame update
    void Start()
    {
        //TestWhileLoop();
        TestDoWhileLoop();
    }

    public void TestWhileLoop()
    {
        int i = 0;

        while (i<loops) 
        {
            i++;
            Debug.Log(i);
        }


    }

    public void TestDoWhileLoop()
    {
        int i = 0;

        do
        {
            i++;
            Debug.Log(i);
        } while (i < loops);
    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *