c# stop loop
/* There is another way to break out of a loop if you use
the return command inside a method/function */
class MainClass {
public static void Main (string[] args) {
UnlockDoor();
// after it hits the return statement,
// it will move on to this method
PickUpSword();
}
static bool UnlockDoor()
{
bool doorIsLocked = true;
// this code will keep running
while (doorIsLocked)
{
bool keyFound = TryKey();
// eventually if this stopping condition is true,
// it will break out of the while loop
if (keyFound)
{
// this return statement will break out of the entire method
return true;
}
}
return false;
}
}while (playerIsAlive)
{
// this code will keep running
if (playerIsAlive == false)
{
// eventually if this stopping condition is true,
// it will break out of the while loop
break;
}
}
// rest of the program will continue
Also in C#:
- using in c#
- unity load text resources from subfolder
- order by C#
- unity random float
- autoresetevent
- c# shorten an definition
- how to generate random unique id in c#
- asp.net textarea disable resize
- switch case c# contains
- dontdestroyonload unity
- stateteach.net
- Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
- c# double value with 2 decimal places
- c# add to array
- how to pass an optional parameter in c# mvc asp.net
- c# if statement
- how to compare datetime in c#
- c# code snippet template
- unity deactivate scripts in list
- project tab unity
- unity3d raycast
- unity collider2d contains point
- grab reference from method parameter c#
- unity onclick addlistener