Skip to main content

Command Palette

Search for a command to run...

Difference between break and continue in c#

How to use break and continue statement in C#

Published
1 min read
F
I am an Infrastructure and DevOps Engineer specializing in designing, building, and operating scalable, secure, and highly available cloud infrastructure. My core focus is on Microsoft Azure cloud platforms, Infrastructure as Code (IaC), and DevOps automation to support reliable production systems. I work across cloud infrastructure engineering, DevOps practices, and site reliability engineering (SRE) principles to ensure systems are resilient, observable, and optimized for performance, cost, and scalability. My experience includes designing and managing cloud environments across compute, networking, storage, identity, and security layers. I build Infrastructure as Code solutions using Terraform and Azure Resource Manager (ARM) templates to automate provisioning, configuration, and deployment of cloud resources. I am actively involved in improving system reliability through monitoring, logging, and incident response processes using tools such as Azure Monitor and cloud-native observability solutions. I also participate in on-call operations, production support, and incident management to ensure high availability of critical systems. Security is a core part of my engineering approach. I work with identity and access management (IAM), Azure Active Directory, and cloud security best practices to ensure infrastructure remains compliant, secure, and audit-ready in line with industry standards such as ISO 9001 and ISO 27001. I collaborate with cross-functional teams including software engineers, DevSecOps, and product teams to deliver infrastructure solutions for customer-facing applications and enterprise platforms. My technical interests and growth areas include: Cloud Infrastructure Engineering (Azure, AWS, GCP) Site Reliability Engineering (SRE) Platform Engineering Kubernetes & Container Orchestration Infrastructure as Code (Terraform, ARM) CI/CD Pipeline Automation Distributed Systems & System Design Cloud Security & Identity Management I am passionate about building systems that are not only scalable and efficient but also reliable and easy for engineers to use. I am continuously growing my expertise toward senior-level Infrastructure, SRE, and Platform Engineering roles, including global remote opportunities.

break in c-sharp

The break statement is used to terminate a loop(for, if, while, etc.) or a switch statement on a certain condition. After terminating, the controls will pass to the statements that are present after the break statement, if available.

Code Sample

In the code sample below, jumps out of the loop when i is equal to 5:

using System;

namespace MyApplication

{
    class Program

    {
        static void Main(string[]args)

        {
            for (int i = 0; i < 10; i++)

            {
                if(i == 5)

                {
                    break;
                }
                Console.WriteLine(i);
            }
        }
    }
}

continue in c-sharp

The continue statement breaks one iteration in the loop, if a specified condition occurs, and continues with the next iteration in the loop.

Code Sample

The example below skips the value of 5:

using System;

namespace MyApplication

{
    class Program

    {
        static void Main(string[]args)

        {
            for (int i = 0; i < 10; i++)

            {
                if(i == 5)

                {
                    continue;
                }
                Console.WriteLine(i);
            }


        }
    }
}

Thanks for reading...

Happy Coding!

More from this blog

Building Reliable Systems

93 posts

Insights on Infrastructure, DevOps, SRE, and building reliable systems at scale.