2
Most read
8
Most read
Program Control Statements
Dr. Neeraj Kumar Pandey
Introduction
There are three types of program control statements:-
1. Selection Statements
 if
 switch
2. Iteration Statements
 for
 while
 do-while
 foreach
3.Jump Statements
 break
 goto
 continue
 return
 throw
Switch Statement
 The switch statement tests the value of a given variable (or expression) against a list of case values
and when match is found, a block of statements associated with that case is executed.
 The general form of switch statement is :-
switch(expression)
{
case value-1:
block-1
break;
case value-2:
block-1
break
case value-n:
block-1
break
default:
default –block
break;
}
Switch Statement(Contd.)
using System;
class bulb
{
public static void Main()
{
Console.WriteLine("Select your choice");
Console.WriteLine("London");
Console.WriteLine("Bombay");
Console.WriteLine("Paris");
Console.WriteLine("Type your choice");
String name=Console.ReadLine();
switch(name)
{
case " Bombay":
Console.WriteLine("Bombay:Guide5");
break;
case " London":
Console.WriteLine("London:Guide10");
break;
case " Paris":
Console.WriteLine("Paris:Guide15");
break;
default:
Console.WriteLine("Invalid Choice");
break;
Fallthrough in Switch Statement
 In the absence of break statement in a case block, if the control moves
to the next case block without any problem, it is known as
‘FALLTHROUGH’.
 ‘FALLTHROUGH’ is permitted in C,C++ and JAVA. But C# doesn't
permit automatic fallthrough, if the case block contains executable code.
switch(m)
{
case 1:
x=y;
case 2:
x=y+m;
default :
x=y-m;
}
is an error in C#.
Fallthrough in Switch
Statement(Contd..)
 If we want two consecutive case blocks to be executed continuously,
we have to force the process by using the goto statement.
switch(m)
{
case 1:
x=y;
goto case 2;
case 2:
x=y+m;
goto default;
default:
x=y-m;
break;
}
Fallthrough in Switch
Statement(Contd..)
 The goto mechanisms enable us to jump backward and forward between
cases and therefore arrange labels arbitrarily:
Switch(m)
{
default:
x=y-m;
break;
case 2:
x=y+m;
goto default;
case 1:
x=y;
goto case 2;
}
Foreach statement
 The foreach statement is similar to the for statement but implemented
differently.
foreach(type variable in expression)
{
Body of the Loop
}
public static void Main()
{
foreach(string s in args)
{
Console.WriteLine(s);
}
}
We cannot change the iteration variable during execution.

More Related Content

PPTX
Java swing
PPS
Wrapper class
PPTX
Classes objects in java
PPTX
Vectors in Java
PPTX
Data types in java
PPTX
Java(Polymorphism)
PPTX
Conditional statement c++
PPT
Method overriding
Java swing
Wrapper class
Classes objects in java
Vectors in Java
Data types in java
Java(Polymorphism)
Conditional statement c++
Method overriding

What's hot (20)

PDF
Java I/o streams
PPTX
JAVA AWT
PPTX
STRINGS IN PYTHON
PPTX
Inheritance
PPT
Java Streams
PPTX
Introduction to Object Oriented Programming
PPTX
Polymorphism in java
PPTX
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PPT
Class and object in C++
PPT
9. Input Output in java
PPT
Oops ppt
PPTX
String, string builder, string buffer
PPT
Network programming in Java
PPTX
Control structures in java
PPT
Switch statements in Java
PPTX
Java exception handling
PPTX
Constructor overloading & method overloading
PPTX
Static Data Members and Member Functions
PPTX
Interface in java
Java I/o streams
JAVA AWT
STRINGS IN PYTHON
Inheritance
Java Streams
Introduction to Object Oriented Programming
Polymorphism in java
Oops concepts || Object Oriented Programming Concepts in Java
Class and object in C++
9. Input Output in java
Oops ppt
String, string builder, string buffer
Network programming in Java
Control structures in java
Switch statements in Java
Java exception handling
Constructor overloading & method overloading
Static Data Members and Member Functions
Interface in java
Ad

Similar to Program control statements in c# (20)

PPTX
Flow Control (C#)
PPTX
handling input output and control statements
PPTX
Btech i pic u-3 handling input output and control statements
PPTX
Mca i pic u-3 handling input output and control statements
PPT
C++ chapter 4
PPTX
Diploma ii cfpc u-3 handling input output and control statements
PPTX
Bsc cs pic u-3 handling input output and control statements
PPT
Flow of Control
DOCX
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
PDF
Control statements anil
PPTX
Comp ppt (1)
PDF
Control flow statements in java web applications
PDF
Controls & Loops in C
PPTX
Programming Fundamentals in C++ structures
PPT
2. Control structures with for while and do while.ppt
PPT
Decision making in C(2020-2021) statements
PPTX
Control Structures.pptx
PPTX
Control statement-Selective
PPTX
C Programming - Decision making, Looping
PPT
Lecture 3
Flow Control (C#)
handling input output and control statements
Btech i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
C++ chapter 4
Diploma ii cfpc u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
Flow of Control
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
Control statements anil
Comp ppt (1)
Control flow statements in java web applications
Controls & Loops in C
Programming Fundamentals in C++ structures
2. Control structures with for while and do while.ppt
Decision making in C(2020-2021) statements
Control Structures.pptx
Control statement-Selective
C Programming - Decision making, Looping
Lecture 3
Ad

More from Dr.Neeraj Kumar Pandey (20)

PPTX
Delegates and events in C#
PPTX
Structure in c#
PPTX
Strings in c#
PPTX
Operators and expression in c#
PPTX
Method parameters in c#
PPTX
Enumeration in c#
PPTX
C# classes objects
PPTX
Dot net assembly
PPT
Cloud introduction
PPTX
Role of cloud computing in scm
PPTX
PPTX
cloud computing Multi cloud
PPTX
Ibm bluemix case study
PPTX
Business cases for the need of cloud computing
PPT
cloud computing:Types of virtualization
PPTX
cloud computing: Vm migration
PPTX
Cloud Computing: Virtualization
PPT
Dot net introduction
PPTX
C# lecture 2: Literals , Variables and Data Types in C#
PPTX
C# lecture 1: Introduction to Dot Net Framework
Delegates and events in C#
Structure in c#
Strings in c#
Operators and expression in c#
Method parameters in c#
Enumeration in c#
C# classes objects
Dot net assembly
Cloud introduction
Role of cloud computing in scm
cloud computing Multi cloud
Ibm bluemix case study
Business cases for the need of cloud computing
cloud computing:Types of virtualization
cloud computing: Vm migration
Cloud Computing: Virtualization
Dot net introduction
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 1: Introduction to Dot Net Framework

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
SaaS reusability assessment using machine learning techniques
PDF
giants, standing on the shoulders of - by Daniel Stenberg
NewMind AI Weekly Chronicles – August ’25 Week IV
Convolutional neural network based encoder-decoder for efficient real-time ob...
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Basics of Cloud Computing - Cloud Ecosystem
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
Comparative analysis of machine learning models for fake news detection in so...
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
sbt 2.0: go big (Scala Days 2025 edition)
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Early detection and classification of bone marrow changes in lumbar vertebrae...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Training Program for knowledge in solar cell and solar industry
4 layer Arch & Reference Arch of IoT.pdf
Co-training pseudo-labeling for text classification with support vector machi...
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
MuleSoft-Compete-Deck for midddleware integrations
SaaS reusability assessment using machine learning techniques
giants, standing on the shoulders of - by Daniel Stenberg

Program control statements in c#

  • 1. Program Control Statements Dr. Neeraj Kumar Pandey
  • 2. Introduction There are three types of program control statements:- 1. Selection Statements  if  switch 2. Iteration Statements  for  while  do-while  foreach 3.Jump Statements  break  goto  continue  return  throw
  • 3. Switch Statement  The switch statement tests the value of a given variable (or expression) against a list of case values and when match is found, a block of statements associated with that case is executed.  The general form of switch statement is :- switch(expression) { case value-1: block-1 break; case value-2: block-1 break case value-n: block-1 break default: default –block break; }
  • 4. Switch Statement(Contd.) using System; class bulb { public static void Main() { Console.WriteLine("Select your choice"); Console.WriteLine("London"); Console.WriteLine("Bombay"); Console.WriteLine("Paris"); Console.WriteLine("Type your choice"); String name=Console.ReadLine(); switch(name) { case " Bombay": Console.WriteLine("Bombay:Guide5"); break; case " London": Console.WriteLine("London:Guide10"); break; case " Paris": Console.WriteLine("Paris:Guide15"); break; default: Console.WriteLine("Invalid Choice"); break;
  • 5. Fallthrough in Switch Statement  In the absence of break statement in a case block, if the control moves to the next case block without any problem, it is known as ‘FALLTHROUGH’.  ‘FALLTHROUGH’ is permitted in C,C++ and JAVA. But C# doesn't permit automatic fallthrough, if the case block contains executable code. switch(m) { case 1: x=y; case 2: x=y+m; default : x=y-m; } is an error in C#.
  • 6. Fallthrough in Switch Statement(Contd..)  If we want two consecutive case blocks to be executed continuously, we have to force the process by using the goto statement. switch(m) { case 1: x=y; goto case 2; case 2: x=y+m; goto default; default: x=y-m; break; }
  • 7. Fallthrough in Switch Statement(Contd..)  The goto mechanisms enable us to jump backward and forward between cases and therefore arrange labels arbitrarily: Switch(m) { default: x=y-m; break; case 2: x=y+m; goto default; case 1: x=y; goto case 2; }
  • 8. Foreach statement  The foreach statement is similar to the for statement but implemented differently. foreach(type variable in expression) { Body of the Loop } public static void Main() { foreach(string s in args) { Console.WriteLine(s); } } We cannot change the iteration variable during execution.