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);
}
}