✔ C# Tutorial
✔ C# Basic
✔ C# Control Statement
✔ C# Function
✔ C# Arrays
✔ C# Object Class
✔ C# Properties
✔ C# Inheritance
✔ C# Polymorphism
✔ C# Abstraction
✔ C# Namespace
✔ C# Exception Handling
✔ C# Collections
✔ C# Misc
goto
Now, the goto statement is like having a teleportation device in your code. While it can be powerful, use it cautiously as it can make your code less readable.
Here’s a glimpse of goto in action:
using System;
class GotoExample
{
static void Main()
{
int counter = 0;
start:
Console.WriteLine($”Current count: {counter}”);
if (counter < 5)
{
counter++;
goto start; // Jumps to the ‘start’ label
}
}
}
In this example, we create a label start, and when the condition is met, we jump back to that label, creating a loop-like behavior.