- Home /
Question is off-topic or not relevant
Question about the "WhileLoop" tutorial
Link to the tutorial: http://unity3d.com/learn/tutorials/modules/beginner/scripting/loops (00:00 - 01:06)
Code used to demonastrate WhileLoop
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--;
}
}
}
Console Output:
I've washed a cup!
UnityEngine.Debug:Log(Object) I've
washed a cup!
UnityEngine.Debug:Log(Object) I've
washed a cup!
UnityEngine.Debug:Log(Object) I've
washed a cup!
UnityEngine.Debug:Log(Object)
What I don't understand is that, since cupsInTheSink variable is set to 4, why doesn't the loop just keep on going?
This isn't a Unity question, it's just basic program$$anonymous$$g.
Follow this Question
Related Questions
Do-While loop 2 Answers
or doesn't work in while loops? 1 Answer
Decrease a value every second? 3 Answers
While loop issues in Update() vs. Start() 0 Answers
infinite loop 2 Answers