Admin Name
Dashboard
Categorey
Sub Categorey
Artilces
Users
Settings
Logout
Welcome to the Admin Panel
Create Post
Select Categorey
- Select -
coding
Select Sub Categorey
Title Name :
Defination :
Jump statements in C# control the flow of execution by altering the natural order. They are used to: break – Exit a loop or switch block prematurely. continue – Skip the current iteration of a loop and jump to the next. return – Exit from a method and optionally return a val
Code :
using System; class Program { static void Main() { for (int i = 1; i <= 5; i++) { if (i == 3) { Console.WriteLine("Breaking at i = " + i); break; } Console.WriteLine("i = " + i); } Console.WriteLine("---"); for (int j = 1; j <= 5; j++) { if (j == 3) { Console.WriteLine("Skipping i = " + j); continue; } Console.WriteLine("j = " + j); } } }
Code Part 2 :
using System; class Program { static void Main() { Console.WriteLine("Result: " + AddNumbers(5, 3)); Console.WriteLine("Result: " + AddNumbers(0, 3)); } static int AddNumbers(int a, int b) { if (a == 0) { Console.WriteLine("Invalid input. Returning 0."); return 0; } return a + b; } }
Upload Image 1
Upload Image 2
Summary
In the first loop (for i = 1 to 5): When i == 3, the break executes. It exits the loop immediately, so values after 3 are not printed. ?? In the second loop: When j == 3, the continue statement runs. That iteration is skipped, and it jumps directly to j = 4. ?? In the third example: If a == 0, the return statement runs early and exits the AddNumbers() method. It doesn’t execute a + b, and instead returns 0.
YouTube Link
Seo Title
Meta Keywords
Meta Description
Introduction to C#
Edit
Variables and Data Types in C#
Edit
Operators in C#
Edit
Control Statements in C# – if, else, switch, and loops Explained
Edit
Loops in C# – for, while, do while, and foreach
Edit
Jump Statements in C# – break, continue, return Explained with Examples
Edit
Conditional Statements in C# if, else if, else, switch Explained with Examples
Edit
Loops in C# – For, While, and Do While with Examples
Edit
Hrjejd
Edit