SlideShare a Scribd company logo
1 of 10
Lesson 2
Learn C#. Series of C# lessons
http://csharp.honcharuk.me/lesson-2
Agenda
• Arrays
• Conditional statements: if, if-else, switch
• Loops: for, foreach, while and do…while
One-dimensional arrays
• An array is a special variable, which can hold more than one value at a time
int[] a = new int[6];
a[0] = 12;
a[1] = 2;
a[2] = 1;
a[3] = 232;
a[4] = 16;
a[5] = 99;
Console.WriteLine(a[5]);//prints '99'
if and if-else statements
Condition
Previous
calculations
Some
calculations
Some
calculations
True False
Other program
calculations
Condition
Previous
calculations
Some
calculations
True
Other programs
calculations
ifIf-else
switch statement
expression
code block 1
code block 2
code block 3
code block N
case 1
case 1
case 1
default
Console.WriteLine("Enter girl's name:");
string girlName = Console.ReadLine();
switch (girlName)
{
case "Kate":
Console.WriteLine("Just ignore her.");
break;
case "Samanta":
Console.WriteLine("Give her your phone number!");
break;
case "Melissa":
Console.WriteLine("She has a birthday pretty soon!");
break;
default:
Console.WriteLine("Sorry, I don't know {0}", girlName);
break;
} Console.WriteLine("Enter girl's name:");
string girlName = Console.ReadLine();
if (girlName == "Kate")
{
Console.WriteLine("Just ignore her.");
}
else if (girlName == "Samanta")
{
Console.WriteLine("Give her your phone number!");
}
else if (girlName == "Melissa")
{
Console.WriteLine("She has a birthday pretty soon!");
}
else
{
Console.WriteLine("Sorry, I don't know {0}", girlName);
}
Loop operators: while, do-while
Condition
Previous calculations
body
True
False
Other calculations
Condition
Previous calculations
body
True
False
Other calculations
int moneyInWallet = 100;
int iPhonePrice = 499;
while (moneyInWallet < iPhonePrice)
{
//keep on making money
moneyInWallet = moneyInWallet + 1;
}
while
int moneyInWallet = 0;
int iPhonePrice = 499;
do
{
//keep on making money
moneyInWallet++; //increment
}
while (moneyInWallet > iPhonePrice);
do-while
Loop operators: for
Condition
initialization
body
True
False
Counter change
Other calculations
for (int index = 1; index < 10; index++)
{//Body
Console.WriteLine("Number {0}", index);
}
if and for demo
for condition
initialization
True
False
Counter change
Other calculations
If condition
Some actions
True
False
for (int index = 0; index <= 10; index++)
{
if (index%2 == 0)
{
Console.WriteLine($"Number {index} in an even number");
}
}
Loops operators
• break
• continue
Thank you!
Questions?

More Related Content

Viewers also liked

Laptops guidelines and items to consider
Laptops guidelines and items to considerLaptops guidelines and items to consider
Laptops guidelines and items to considerjenblack4
 
Konkurss -jvg11b 7
Konkurss  -jvg11b 7Konkurss  -jvg11b 7
Konkurss -jvg11b 7Rudybobudy
 
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...Notis Mitarachi
 
Mark rothko daugavpils 8
Mark rothko daugavpils 8Mark rothko daugavpils 8
Mark rothko daugavpils 8Rudybobudy
 
Skrillex biography
Skrillex biographySkrillex biography
Skrillex biographyNuria Tuda
 
Tina Stiegler
Tina StieglerTina Stiegler
Tina StieglerStormkast
 
Alexander Cappelen
Alexander CappelenAlexander Cappelen
Alexander CappelenStormkast
 
Gerry McGovern Transform
Gerry McGovern TransformGerry McGovern Transform
Gerry McGovern TransformStormkast
 
Aurelius Wachstumskapital Company Presentation
Aurelius Wachstumskapital Company PresentationAurelius Wachstumskapital Company Presentation
Aurelius Wachstumskapital Company PresentationMatthias Schneck
 
Various popular methods for coal belt treatment
Various popular methods for coal belt treatmentVarious popular methods for coal belt treatment
Various popular methods for coal belt treatmentJNB Laboratories
 
Embedded System Design latest
Embedded System Design latestEmbedded System Design latest
Embedded System Design latestDeepak Chouhan
 
EMBEDDED WEB SERVER
EMBEDDED WEB SERVEREMBEDDED WEB SERVER
EMBEDDED WEB SERVERkavya Reddy
 
Propuestas para mejorar el colegio.
Propuestas para mejorar el colegio.Propuestas para mejorar el colegio.
Propuestas para mejorar el colegio.Marcos Ramos
 
Embedded device hacking Session i
Embedded device hacking Session iEmbedded device hacking Session i
Embedded device hacking Session iMalachi Jones
 

Viewers also liked (16)

Laptops guidelines and items to consider
Laptops guidelines and items to considerLaptops guidelines and items to consider
Laptops guidelines and items to consider
 
Konkurss -jvg11b 7
Konkurss  -jvg11b 7Konkurss  -jvg11b 7
Konkurss -jvg11b 7
 
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...
Αναφορά Ν. Μηταράκη σχετικά με τον ελάχιστο αριθμό μαθητών και τη μοριοδότηση...
 
Mark rothko daugavpils 8
Mark rothko daugavpils 8Mark rothko daugavpils 8
Mark rothko daugavpils 8
 
Skrillex biography
Skrillex biographySkrillex biography
Skrillex biography
 
Tina Stiegler
Tina StieglerTina Stiegler
Tina Stiegler
 
Alexander Cappelen
Alexander CappelenAlexander Cappelen
Alexander Cappelen
 
Gerry McGovern Transform
Gerry McGovern TransformGerry McGovern Transform
Gerry McGovern Transform
 
Sada shiva profile
Sada shiva profileSada shiva profile
Sada shiva profile
 
Aurelius Wachstumskapital Company Presentation
Aurelius Wachstumskapital Company PresentationAurelius Wachstumskapital Company Presentation
Aurelius Wachstumskapital Company Presentation
 
Various popular methods for coal belt treatment
Various popular methods for coal belt treatmentVarious popular methods for coal belt treatment
Various popular methods for coal belt treatment
 
Embedded System Design latest
Embedded System Design latestEmbedded System Design latest
Embedded System Design latest
 
EMBEDDED WEB SERVER
EMBEDDED WEB SERVEREMBEDDED WEB SERVER
EMBEDDED WEB SERVER
 
Propuestas para mejorar el colegio.
Propuestas para mejorar el colegio.Propuestas para mejorar el colegio.
Propuestas para mejorar el colegio.
 
Embedded device hacking Session i
Embedded device hacking Session iEmbedded device hacking Session i
Embedded device hacking Session i
 
Bukiet Przyjazni
Bukiet PrzyjazniBukiet Przyjazni
Bukiet Przyjazni
 

Similar to Lesson2

4b C switch structure .ppt
4b C switch structure .ppt4b C switch structure .ppt
4b C switch structure .pptGowthamiRangaraj
 
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#Hawkman Academy
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23Bilal Ahmed
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignmentmcollison
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptxssuserfb3c3e
 
關於測試,我說的其實是......
關於測試,我說的其實是......關於測試,我說的其實是......
關於測試,我說的其實是......hugo lu
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven PractisesRobert MacLean
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptMahyuddin8
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptghoitsun
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 
07 control+structures
07 control+structures07 control+structures
07 control+structuresbaran19901990
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
programming c language.
programming c language. programming c language.
programming c language. Abdul Rehman
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection StatementsSzeChingChen
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptSuleman Khan
 

Similar to Lesson2 (20)

4b C switch structure .ppt
4b C switch structure .ppt4b C switch structure .ppt
4b C switch structure .ppt
 
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#
 
CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23CS101- Introduction to Computing- Lecture 23
CS101- Introduction to Computing- Lecture 23
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
關於測試,我說的其實是......
關於測試,我說的其實是......關於測試,我說的其實是......
關於測試,我說的其實是......
 
Lecture1.pdf
Lecture1.pdfLecture1.pdf
Lecture1.pdf
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
 
ch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.pptch02-primitive-data-definite-loops.ppt
ch02-primitive-data-definite-loops.ppt
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
programming c language.
programming c language. programming c language.
programming c language.
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
tick cross game
tick cross gametick cross game
tick cross game
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 

More from Alex Honcharuk (8)

Lesson11
Lesson11Lesson11
Lesson11
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Lesson9
Lesson9Lesson9
Lesson9
 
Lesson8
Lesson8Lesson8
Lesson8
 
Lesson6
Lesson6Lesson6
Lesson6
 
Lesson5
Lesson5Lesson5
Lesson5
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Lesson1
Lesson1Lesson1
Lesson1
 

Recently uploaded

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

Lesson2

  • 1. Lesson 2 Learn C#. Series of C# lessons http://csharp.honcharuk.me/lesson-2
  • 2. Agenda • Arrays • Conditional statements: if, if-else, switch • Loops: for, foreach, while and do…while
  • 3. One-dimensional arrays • An array is a special variable, which can hold more than one value at a time int[] a = new int[6]; a[0] = 12; a[1] = 2; a[2] = 1; a[3] = 232; a[4] = 16; a[5] = 99; Console.WriteLine(a[5]);//prints '99'
  • 4. if and if-else statements Condition Previous calculations Some calculations Some calculations True False Other program calculations Condition Previous calculations Some calculations True Other programs calculations ifIf-else
  • 5. switch statement expression code block 1 code block 2 code block 3 code block N case 1 case 1 case 1 default Console.WriteLine("Enter girl's name:"); string girlName = Console.ReadLine(); switch (girlName) { case "Kate": Console.WriteLine("Just ignore her."); break; case "Samanta": Console.WriteLine("Give her your phone number!"); break; case "Melissa": Console.WriteLine("She has a birthday pretty soon!"); break; default: Console.WriteLine("Sorry, I don't know {0}", girlName); break; } Console.WriteLine("Enter girl's name:"); string girlName = Console.ReadLine(); if (girlName == "Kate") { Console.WriteLine("Just ignore her."); } else if (girlName == "Samanta") { Console.WriteLine("Give her your phone number!"); } else if (girlName == "Melissa") { Console.WriteLine("She has a birthday pretty soon!"); } else { Console.WriteLine("Sorry, I don't know {0}", girlName); }
  • 6. Loop operators: while, do-while Condition Previous calculations body True False Other calculations Condition Previous calculations body True False Other calculations int moneyInWallet = 100; int iPhonePrice = 499; while (moneyInWallet < iPhonePrice) { //keep on making money moneyInWallet = moneyInWallet + 1; } while int moneyInWallet = 0; int iPhonePrice = 499; do { //keep on making money moneyInWallet++; //increment } while (moneyInWallet > iPhonePrice); do-while
  • 7. Loop operators: for Condition initialization body True False Counter change Other calculations for (int index = 1; index < 10; index++) {//Body Console.WriteLine("Number {0}", index); }
  • 8. if and for demo for condition initialization True False Counter change Other calculations If condition Some actions True False for (int index = 0; index <= 10; index++) { if (index%2 == 0) { Console.WriteLine($"Number {index} in an even number"); } }

Editor's Notes

  1. http://www.functionx.com/csharp3/Lesson21.htm