Swich Statement in C | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

Swich Statement in C

Date- Sep 23,2023

1878


In C, the switch statement is a control structure used for making decisions based on the value of a variable or expression. It allows you to test a variable against a list of values (cases) and execute a block of code associated with the first matching case.

Here's how the switch statement works:

  1. 1. The switch keyword is followed by an expression (usually a variable) enclosed in parentheses. This expression is evaluated to determine which case to execute.

  2. 2. Inside the switch block, you list one or more case labels. Each case label represents a possible value that the expression might have.

  3. 3. When the switch statement is executed, it compares the value of the expression to each case constant sequentially.

  4. 4. If a match is found (i.e., if the expression's value is equal to a case constant), the code block associated with that case is executed.

  5. 5. The break statement is used to exit the switch block. Without break, the execution would continue into subsequent case blocks until a break is encountered or the switch block ends.

  6. 6. If none of the case values matches the expression, the default block is executed (if it exists). The default block is optional and serves as a fallback.









Here's the basic syntax of a switch statement:
switch (expression) {
    case constant 1:
        // Code to be executed if expression equals constant 1
        break;
    case constant 2:
        // Code to be executed if expression equals constant 2
        break;
   
    default:
        // Code to be executed if no case matches
}
In this example, the user enters a number, and the switch statement determines which option was chosen based on the input value. If the input doesn't match any of the cases, the default block is executed.

Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1210
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts