SlideShare uma empresa Scribd logo
1 de 29
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com
For video visit
www.dotnetvideotutorial.com
FlowControl
Selection
Statements
If / if – else / else if
switch - case
Loops
for
while
do while
for each
Jump Statements
goto
break
continue
Return
throw
Agenda
Selection Statements
 A selection statement causes the program control to be
transferred to a specific flow based upon whether a certain
condition is true or not.
 The following keywords are used in selection statements:
 if
 else
 switch
 case
 default
www.dotnetvideotutorial.com
If-else
 The if statement selects a statement for execution
based on the value of a Boolean expression.
 Executes if block if condition is true and else block if
condition is false
 else block is optional
www.dotnetvideotutorial.com
int no1, no2;
Console.Write("Enter Number1: ");
no1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number2: ");
no2 = Convert.ToInt32(Console.ReadLine());
if (no1 > no2)
{
Console.WriteLine("no1 is greater than no2");
}
else
{
Console.WriteLine("no2 is greater than no1");
}
if - else
Optional
www.dotnetvideotutorial.com
Nested if-else
 if-else can be nested either inside other if or
else block
www.dotnetvideotutorial.com
Nested if
if (no1 > no2)
{
Console.WriteLine("no1 is greater than no2");
}
else
{
if(no1 < no2)
Console.WriteLine("no2 is greater than no1");
else
Console.WriteLine("no1 is equal to no2");
}
www.dotnetvideotutorial.com
else-if
 else –if can be use to avoid deep nesting in case
of multiple conditions
www.dotnetvideotutorial.com
else if
if (no1 > no2)
{
Console.WriteLine("no1 is greater than no2");
}
else if (no2 > no1)
{
Console.WriteLine("no2 is greater than no1");
}
else
{
Console.WriteLine("no1 is equal to no2");
}
www.dotnetvideotutorial.com
switch-case
 The switch statement is a control statement that
handles multiple selections and enumerations by
passing control to one of the case statements within
its body
www.dotnetvideotutorial.com
switch-case
int no1, no2, result = 0;
char op;
Console.Write("Enter Number1: ");
no1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Number2: ");
no2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter Operator (+,-,*,/): ");
op = Convert.ToChar(Console.ReadLine());
www.dotnetvideotutorial.com
switch (op)
{
case '+':
result = no1 + no2;
break;
case '-':
result = no1 - no2;
break;
case '*':
result = no1 * no2;
break;
case '/':
result = no1 / no2;
break;
default:
Console.WriteLine("Invalid Operator");
break;
}
Console.WriteLine("Result = " + result);
break is compulsory
default is optional
Swith-case fallthrough
 Swith-case fallthrough can be used to execute same
block for multiple cases.
 It can be achived using empty case block
www.dotnetvideotutorial.com
Console.Write("Enter Ratings (0 to 5): ");
int ratings = Convert.ToInt32(Console.ReadLine());
switch(ratings)
{
case 0:
case 1:
Console.WriteLine("Poor");
break;
case 2:
case 3:
Console.WriteLine("Average");
break;
case 4:
Console.WriteLine("Good");
break;
}
Only empty case allow
block without break
statement
Swith-case fallthrough
FlowControl
Selection
Statements
If / if – else / else if
switch - case
Loops
for
while
do while
for each
Jump Statements
goto
break
continue
Return
throw
Agenda
Loops
 Loop executes a block of code repeatedly until a
certain condition is met.
 C# provides four loops
 for
 while
 do. . .while
 foreach
www.dotnetvideotutorial.com
for
for (initializer; condition; iterator)
{
statement(s)
}
The initializer is the expression evaluated before the
first loop is executed
The condition is the expression checked
before each new iteration of the loop
The iterator is an expression evaluated after
each iteration
www.dotnetvideotutorial.com
for
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Hello");
}
www.dotnetvideotutorial.com
while
int i = 0;
while(i < 10)
{
Console.WriteLine(i);
i++;
}
Initializer
Condition
Iterator
www.dotnetvideotutorial.com
do...while
int i = 0;
do
{
Console.WriteLine("Hello " + i);
i++;
} while (i < 10);
Initializer
Condition
Iterator
www.dotnetvideotutorial.com
foreach
int[] marks = { 50, 35, 65, 43, 65 };
foreach (int m in marks)
{
Console.WriteLine(m);
} 50 35 65 43 65
m
marks
www.dotnetvideotutorial.com
Nested Loop
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 5; j++)
{
Console.WriteLine("i={0} j={1}",i,j);
}
Console.WriteLine();
}
www.dotnetvideotutorial.com
FlowControl
Selection
Statements
If / if – else / else if
switch - case
Loops
for
while
do while
for each
Jump Statements
goto
break
continue
Return
throw
Agenda
Jump Statements
 Branching is performed using jump statements, which
cause an immediate transfer of the program control.
The following keywords are used in jump statements:
 break
 continue
 goto
 return
 throw
www.dotnetvideotutorial.com
goto
static void Main(string[] args)
{
label1:
Console.WriteLine("Do you like this tutorial?");
Console.Write("Enter Y or N: ");
char response = Convert.ToChar(Console.ReadLine());
if (response == 'N' || response == 'n')
goto label1;
Console.WriteLine("O Thanks!!!");
}
www.dotnetvideotutorial.com
break
for (int i = 0; i < 10; i++)
{
if (i == 6)
break;
Console.WriteLine("i = " + i);
}
www.dotnetvideotutorial.com
continue
for (int i = 0; i < 10; i++)
{
if (i == 6)
continue;
Console.WriteLine("i = " + i);
}
www.dotnetvideotutorial.com
Bhushan Mulmule
bhushan.mulmule@dotnetvideotutorial.com
www.dotnetvideotutorial.com

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
IF Else logic in c#
IF Else logic in c#IF Else logic in c#
IF Else logic in c#
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
While loop
While loopWhile loop
While loop
 
Code generator
Code generatorCode generator
Code generator
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Quadric surfaces
Quadric surfacesQuadric surfaces
Quadric surfaces
 
C programming enumeration
C programming enumerationC programming enumeration
C programming enumeration
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Loops
LoopsLoops
Loops
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
Debugging
DebuggingDebugging
Debugging
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 

Destaque

Destaque (12)

C# looping basic
C# looping basicC# looping basic
C# looping basic
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Flow control in computer
Flow control in computerFlow control in computer
Flow control in computer
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Module15: Sliding Windows Protocol and Error Control
Module15: Sliding Windows Protocol and Error Control Module15: Sliding Windows Protocol and Error Control
Module15: Sliding Windows Protocol and Error Control
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Flow Control
Flow ControlFlow Control
Flow Control
 

Semelhante a Flow Control (C#)

Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structuresayshasafdarwaada
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)Jyoti Bhardwaj
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.pptManojKhadilkar1
 
Loop control statements
Loop control statementsLoop control statements
Loop control statementsJaya Kumari
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Deepak Singh
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
Bansal presentation (1).pptx
Bansal presentation (1).pptxBansal presentation (1).pptx
Bansal presentation (1).pptxAbhiYadav655132
 
Introduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptxIntroduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptxofeliacanaria1
 
Xamarin: Branching and Looping
Xamarin: Branching and LoopingXamarin: Branching and Looping
Xamarin: Branching and LoopingEng Teong Cheah
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptxAbhiYadav655132
 
What is loops? What is For loop?
What is loops? What is For loop?What is loops? What is For loop?
What is loops? What is For loop?AnuragSrivastava272
 
Control Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptxControl Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptxBansalShrivastava
 

Semelhante a Flow Control (C#) (20)

Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
C sharp chap4
C sharp chap4C sharp chap4
C sharp chap4
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
C language 2
C language 2C language 2
C language 2
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Java Control Statements
Java Control StatementsJava Control Statements
Java Control Statements
 
Control statements
Control statementsControl statements
Control statements
 
Bansal presentation (1).pptx
Bansal presentation (1).pptxBansal presentation (1).pptx
Bansal presentation (1).pptx
 
Introduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptxIntroduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptx
 
Xamarin: Branching and Looping
Xamarin: Branching and LoopingXamarin: Branching and Looping
Xamarin: Branching and Looping
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
 
What is loops? What is For loop?
What is loops? What is For loop?What is loops? What is For loop?
What is loops? What is For loop?
 
Control Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptxControl Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptx
 

Mais de Bhushan Mulmule

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQueryBhushan Mulmule
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Bhushan Mulmule
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Bhushan Mulmule
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Bhushan Mulmule
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Bhushan Mulmule
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Bhushan Mulmule
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginnersBhushan Mulmule
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding InterfacesBhushan Mulmule
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And EnumsBhushan Mulmule
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# ProgrammingBhushan Mulmule
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Bhushan Mulmule
 

Mais de Bhushan Mulmule (16)

Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2Windows Forms For Beginners Part - 2
Windows Forms For Beginners Part - 2
 
Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1Windows Forms For Beginners Part - 1
Windows Forms For Beginners Part - 1
 
NInject - DI Container
NInject - DI ContainerNInject - DI Container
NInject - DI Container
 
Dependency injection for beginners
Dependency injection for beginnersDependency injection for beginners
Dependency injection for beginners
 
Understanding Interfaces
Understanding InterfacesUnderstanding Interfaces
Understanding Interfaces
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Inheritance
InheritanceInheritance
Inheritance
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Methods
MethodsMethods
Methods
 
Arrays, Structures And Enums
Arrays, Structures And EnumsArrays, Structures And Enums
Arrays, Structures And Enums
 
Getting started with C# Programming
Getting started with C# ProgrammingGetting started with C# Programming
Getting started with C# Programming
 
Overview of .Net Framework 4.5
Overview of .Net Framework 4.5Overview of .Net Framework 4.5
Overview of .Net Framework 4.5
 

Último

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Último (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Flow Control (C#)

  • 3. FlowControl Selection Statements If / if – else / else if switch - case Loops for while do while for each Jump Statements goto break continue Return throw Agenda
  • 4. Selection Statements  A selection statement causes the program control to be transferred to a specific flow based upon whether a certain condition is true or not.  The following keywords are used in selection statements:  if  else  switch  case  default www.dotnetvideotutorial.com
  • 5. If-else  The if statement selects a statement for execution based on the value of a Boolean expression.  Executes if block if condition is true and else block if condition is false  else block is optional www.dotnetvideotutorial.com
  • 6. int no1, no2; Console.Write("Enter Number1: "); no1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Number2: "); no2 = Convert.ToInt32(Console.ReadLine()); if (no1 > no2) { Console.WriteLine("no1 is greater than no2"); } else { Console.WriteLine("no2 is greater than no1"); } if - else Optional www.dotnetvideotutorial.com
  • 7. Nested if-else  if-else can be nested either inside other if or else block www.dotnetvideotutorial.com
  • 8. Nested if if (no1 > no2) { Console.WriteLine("no1 is greater than no2"); } else { if(no1 < no2) Console.WriteLine("no2 is greater than no1"); else Console.WriteLine("no1 is equal to no2"); } www.dotnetvideotutorial.com
  • 9. else-if  else –if can be use to avoid deep nesting in case of multiple conditions www.dotnetvideotutorial.com
  • 10. else if if (no1 > no2) { Console.WriteLine("no1 is greater than no2"); } else if (no2 > no1) { Console.WriteLine("no2 is greater than no1"); } else { Console.WriteLine("no1 is equal to no2"); } www.dotnetvideotutorial.com
  • 11. switch-case  The switch statement is a control statement that handles multiple selections and enumerations by passing control to one of the case statements within its body www.dotnetvideotutorial.com
  • 12. switch-case int no1, no2, result = 0; char op; Console.Write("Enter Number1: "); no1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Number2: "); no2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Operator (+,-,*,/): "); op = Convert.ToChar(Console.ReadLine()); www.dotnetvideotutorial.com
  • 13. switch (op) { case '+': result = no1 + no2; break; case '-': result = no1 - no2; break; case '*': result = no1 * no2; break; case '/': result = no1 / no2; break; default: Console.WriteLine("Invalid Operator"); break; } Console.WriteLine("Result = " + result); break is compulsory default is optional
  • 14. Swith-case fallthrough  Swith-case fallthrough can be used to execute same block for multiple cases.  It can be achived using empty case block www.dotnetvideotutorial.com
  • 15. Console.Write("Enter Ratings (0 to 5): "); int ratings = Convert.ToInt32(Console.ReadLine()); switch(ratings) { case 0: case 1: Console.WriteLine("Poor"); break; case 2: case 3: Console.WriteLine("Average"); break; case 4: Console.WriteLine("Good"); break; } Only empty case allow block without break statement Swith-case fallthrough
  • 16. FlowControl Selection Statements If / if – else / else if switch - case Loops for while do while for each Jump Statements goto break continue Return throw Agenda
  • 17. Loops  Loop executes a block of code repeatedly until a certain condition is met.  C# provides four loops  for  while  do. . .while  foreach www.dotnetvideotutorial.com
  • 18. for for (initializer; condition; iterator) { statement(s) } The initializer is the expression evaluated before the first loop is executed The condition is the expression checked before each new iteration of the loop The iterator is an expression evaluated after each iteration www.dotnetvideotutorial.com
  • 19. for for (int i = 0; i < 10; i++) { Console.WriteLine("Hello"); } www.dotnetvideotutorial.com
  • 20. while int i = 0; while(i < 10) { Console.WriteLine(i); i++; } Initializer Condition Iterator www.dotnetvideotutorial.com
  • 21. do...while int i = 0; do { Console.WriteLine("Hello " + i); i++; } while (i < 10); Initializer Condition Iterator www.dotnetvideotutorial.com
  • 22. foreach int[] marks = { 50, 35, 65, 43, 65 }; foreach (int m in marks) { Console.WriteLine(m); } 50 35 65 43 65 m marks www.dotnetvideotutorial.com
  • 23. Nested Loop for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { Console.WriteLine("i={0} j={1}",i,j); } Console.WriteLine(); } www.dotnetvideotutorial.com
  • 24. FlowControl Selection Statements If / if – else / else if switch - case Loops for while do while for each Jump Statements goto break continue Return throw Agenda
  • 25. Jump Statements  Branching is performed using jump statements, which cause an immediate transfer of the program control. The following keywords are used in jump statements:  break  continue  goto  return  throw www.dotnetvideotutorial.com
  • 26. goto static void Main(string[] args) { label1: Console.WriteLine("Do you like this tutorial?"); Console.Write("Enter Y or N: "); char response = Convert.ToChar(Console.ReadLine()); if (response == 'N' || response == 'n') goto label1; Console.WriteLine("O Thanks!!!"); } www.dotnetvideotutorial.com
  • 27. break for (int i = 0; i < 10; i++) { if (i == 6) break; Console.WriteLine("i = " + i); } www.dotnetvideotutorial.com
  • 28. continue for (int i = 0; i < 10; i++) { if (i == 6) continue; Console.WriteLine("i = " + i); } www.dotnetvideotutorial.com