Repository navigation
EN CSharp Loops
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
for specifies the initial action, condition and change; foreach iterates through the sequence; while checks the condition before iteration; do - after it. break ends the loop, continue moves on to the next iteration, return exits the method or script.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
for (int i = 0; i < 3; i++)
System.Console.WriteLine(i);Result:
0
1
2
for (int attempt = 1; attempt <= 3; attempt++)
{
UO.Print($"Attempt {attempt}");
await WaitAsync(100);
}string[] names = ["self", "backpack", "lasttarget"];
foreach (string name in names)
{
if (name == "backpack") continue;
UO.Print(UO.GetSerial(name));
}int left = 3;
while (left > 0)
{
left--;
await WaitAsync(50);
}
do
{
UO.Print("Runs at least once");
} while (false);Infinite background scripts should have a clear stop and wait condition when waiting for an external state. goto exists in the language, but regular loops and methods are usually clearer.
Official documentation: Loops, break, continue and return - Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE