- 如何提前跳出循环
- 使用 break
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ForOverview : MonoBehaviour
{
public int num=0;
// Start is called before the first frame update
void Start()
{
for (int i = 1; i < 100; i++)
{
num++; // 每次循环加1
if (i == 50) // 当循环 50 次后跳出循环
{
break;
}
}
}
// Update is called once per frame
void Update()
{
}
}