SlideShare a Scribd company logo
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

PDF
Mathematicians: Trust, but Verify
PPTX
12. Java Exceptions and error handling
PDF
Week 4
PDF
NSC #2 - D2 06 - Richard Johnson - SAGEly Advice
PPTX
Introduction to Julia
PDF
17 exception handling - ii
PPTX
JPC#8 Introduction to Java Programming
PPTX
Simware framework hello world: A webinar
Mathematicians: Trust, but Verify
12. Java Exceptions and error handling
Week 4
NSC #2 - D2 06 - Richard Johnson - SAGEly Advice
Introduction to Julia
17 exception handling - ii
JPC#8 Introduction to Java Programming
Simware framework hello world: A webinar

Viewers also liked (16)

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

Similar to Lesson2 (20)

DOCX
C# language basics (Visual Studio)
DOCX
C# language basics (Visual studio)
PPT
For Beginners - C#
PPTX
Week 1: Getting Your Hands Dirty - Part 1
PPTX
Session#2
PPTX
Chapter3: fundamental programming
DOCX
Oops pramming with examples
PPSX
C# - Part 1
PPTX
Operators loops conditional and statements
PPTX
Spf Chapter5 Conditional Logics
DOCX
Branching
PPTX
Visual Programing basic lectures 7.pptx
PDF
Learn C# Programming - Nullables & Arrays
PDF
w=iu006m2m=a9'[5n4.pdfhhhhhhhhhhhjjhhjjj
PPTX
C# basics
PPTX
c#(loops,arrays)
PDF
C# Dot net unit-2.pdf
PPTX
Intro to C# - part 2.pptx emerging technology
PPT
C# language basics (Visual Studio)
C# language basics (Visual studio)
For Beginners - C#
Week 1: Getting Your Hands Dirty - Part 1
Session#2
Chapter3: fundamental programming
Oops pramming with examples
C# - Part 1
Operators loops conditional and statements
Spf Chapter5 Conditional Logics
Branching
Visual Programing basic lectures 7.pptx
Learn C# Programming - Nullables & Arrays
w=iu006m2m=a9'[5n4.pdfhhhhhhhhhhhjjhhjjj
C# basics
c#(loops,arrays)
C# Dot net unit-2.pdf
Intro to C# - part 2.pptx emerging technology
Ad

More from Alex Honcharuk (8)

PPTX
Lesson11
PPTX
Lesson 10
PPTX
PPTX
PPTX
PPTX
PPTX
Lesson 4
PPTX
Lesson11
Lesson 10
Lesson 4

Recently uploaded (20)

PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Current and future trends in Computer Vision.pptx
PPT
Total quality management ppt for engineering students
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Well-logging-methods_new................
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
UNIT 4 Total Quality Management .pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Fundamentals of Mechanical Engineering.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Current and future trends in Computer Vision.pptx
Total quality management ppt for engineering students
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Well-logging-methods_new................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Internet of Things (IOT) - A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
UNIT 4 Total Quality Management .pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf

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

  • #4: http://www.functionx.com/csharp3/Lesson21.htm