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

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
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
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Recently uploaded (20)

★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
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...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.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
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

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