SlideShare a Scribd company logo
1 of 11
Download to read offline
C# FOR BEGINNERS
LESSON 7
MICHEAL OGUNDERO
CONTACT :
EMAIL – OGUNDEROAYODEJI@GMAIL.COM
Control Structures II: Repitition Structures
CHECKER!
Just before we go into today’s business
Write a program takes as inputs the name of shapes and its
parameters (Triangle, Circle and Square) then calculate the area
of the selected shape and print.
Hint: If user selects ’’Circle’’ it should ask for it’s radius
CHECKER!
Just before we go into today’s business
Write a program takes as inputs:
a, b and c that form a quadratic equation
𝑎𝑥2
+ 𝑏𝑥 + 𝑐 = 0
Your program should be print
• “Real and Distinct roots” if 𝑏2
> 4𝑎𝑐
• “Same roots” if 𝑏2
= 4𝑎𝑐 and
• “Complex Roots” if 𝑏2
< 4𝑎𝑐
INTRODUCTION
Looping in programming language is a way to execute a statement or a
set of statements multiple number of times depending on the result of
condition to be evaluated.
The result of the condition should be true to execute statements within
loops.
INTRODUCTION
Loops are mainly divided into two categories:
Entry Controlled Loops: are loops in which condition to be tested is present in
beginning of loop body. while loop and for loop are entry controlled loops.
Exit Controlled Loops: are loops in which the testing condition is present at the
end of loop body. do-while is an exit controlled loop.
Note: In Exit Controlled Loops, loop body will be evaluated for at-least one time as
the testing condition is present at the end of loop body.
THEWHILE LOOP
You will get a nice listing
of numbers, from 0 to 4.
The number is first
defined as 0, and each time
the code in the loop is
executed, it's incremented
by one.
class Program
{
static void Main(string[] args)
{
int number = 0;
while(number < 5)
{
Console.WriteLine(number);
number = number + 1;
}
Console.ReadLine();
}
}
The while loop simply executes a block of code as long as the condition you give it is true.
THE WHILE LOOP
Now print your name 20 times using while loop
THE FOR LOOP
This produces the exact
same output, but as you can
see, the for loop is a bit more
compact. It consists of 3
parts - we initialize a variable
for counting, set up a
conditional statement to test
it, and increment the counter
class Program
{
static void Main(string[] args)
{
int number = 5;
for(int i = 0; i < number; i++)
Console.WriteLine(i);
}
}
The for loop is a bit different. It's preferred when you know how many iterations you want, either
because you know the exact amount of iterations, or because you have a variable containing the
amount.
THE DO-WHILE LOOP
The output is the same
though - once the number is
more than 5, the loop is
exited.
class Program
{
static void Main(string[] args)
{
int number = 0;
do
{
Console.WriteLine(number);
number = number + 1;
} while(number < 5);
}
}
do while loop is similar to while loop with only difference that it checks the condition after executing
the statements, i.e it will execute the loop body one time for sure because it checks the condition
after executing the statements.
ASSIGNMENT
1. Write a program in C# Sharp to display the multiplication table of a given integer
2. Write a C# Sharp program to calculate the factorial of a given number
3. Write a program in C# Sharp to read 10 numbers from keyboard and find their
sum and average
4. Write a C# program that converts feet to meters.The program should display
feet from 3 to 30 in three-foot increments and the corresponding meter
equivalents. Use the relationship of 3.28 feet to a meter.
5. Write a C# Sharp program to find the sum of first 10 odd numbers.
REFERENCES
• Visual C# How to Program (6th Edition) (Deitel Series)
• https://www.geeksforgeeks.org/loops-in-c-sharp/
• https://csharp.net-tutorials.com/control-structures/loops/

More Related Content

What's hot

Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab neweyavagal
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newscottbrownnn
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manualkamesh dagia
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program Rumman Ansari
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniquesfika sweety
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)Omkar Rane
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETjinaldesailive
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstractionRaghav Chhabra
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writingUmme habiba
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsnoahjamessss
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2Jomel Penalba
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramDeepak Singh
 

What's hot (17)

Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
Program design techniques
Program design techniquesProgram design techniques
Program design techniques
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NET
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstraction
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
 
Devry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functionsDevry cis-170-c-i lab-4-of-7-functions
Devry cis-170-c-i lab-4-of-7-functions
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
 
C rules
C rulesC rules
C rules
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
 
Tcs nqt 2019 p 2
Tcs nqt 2019 p 2Tcs nqt 2019 p 2
Tcs nqt 2019 p 2
 
[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++[ITP - Lecture 07] Comments in C/C++
[ITP - Lecture 07] Comments in C/C++
 

Similar to csharp repitition structures

CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01Drjilesh
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newLast7693
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdfziyadaslanbey
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxABDULAHAD507571
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation filesantoshkumarhpu
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & ConditionsEbad ullah Qureshi
 
C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 

Similar to csharp repitition structures (20)

CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
Loops
LoopsLoops
Loops
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
03b loops
03b   loops03b   loops
03b loops
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docxLab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
 
C programming assignment presentation file
C programming assignment presentation fileC programming assignment presentation file
C programming assignment presentation file
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions02 Control Structures - Loops & Conditions
02 Control Structures - Loops & Conditions
 
Loops c++
Loops c++Loops c++
Loops c++
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 

More from Micheal Ogundero

datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constantsMicheal Ogundero
 
2 robot types_classifications
2 robot types_classifications2 robot types_classifications
2 robot types_classificationsMicheal Ogundero
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming ConventionsMicheal Ogundero
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-convertedMicheal Ogundero
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharpMicheal Ogundero
 
csharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_referencecsharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_referenceMicheal Ogundero
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesMicheal Ogundero
 

More from Micheal Ogundero (12)

static methods
static methodsstatic methods
static methods
 
c# operators
c# operatorsc# operators
c# operators
 
datatypes_variables_constants
datatypes_variables_constantsdatatypes_variables_constants
datatypes_variables_constants
 
2 robot types_classifications
2 robot types_classifications2 robot types_classifications
2 robot types_classifications
 
History of robots
History of robotsHistory of robots
History of robots
 
c# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventionsc# keywords, identifiers and Naming Conventions
c# keywords, identifiers and Naming Conventions
 
Dictionary and sets-converted
Dictionary and sets-convertedDictionary and sets-converted
Dictionary and sets-converted
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Csharp_List
Csharp_ListCsharp_List
Csharp_List
 
c# Enumerations
c# Enumerationsc# Enumerations
c# Enumerations
 
csharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_referencecsharp_Passing_parameters_by_value_and_reference
csharp_Passing_parameters_by_value_and_reference
 
C# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data TypesC# Value Data Types and Reference Data Types
C# Value Data Types and Reference Data Types
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

csharp repitition structures

  • 1. C# FOR BEGINNERS LESSON 7 MICHEAL OGUNDERO CONTACT : EMAIL – OGUNDEROAYODEJI@GMAIL.COM Control Structures II: Repitition Structures
  • 2. CHECKER! Just before we go into today’s business Write a program takes as inputs the name of shapes and its parameters (Triangle, Circle and Square) then calculate the area of the selected shape and print. Hint: If user selects ’’Circle’’ it should ask for it’s radius
  • 3. CHECKER! Just before we go into today’s business Write a program takes as inputs: a, b and c that form a quadratic equation 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0 Your program should be print • “Real and Distinct roots” if 𝑏2 > 4𝑎𝑐 • “Same roots” if 𝑏2 = 4𝑎𝑐 and • “Complex Roots” if 𝑏2 < 4𝑎𝑐
  • 4. INTRODUCTION Looping in programming language is a way to execute a statement or a set of statements multiple number of times depending on the result of condition to be evaluated. The result of the condition should be true to execute statements within loops.
  • 5. INTRODUCTION Loops are mainly divided into two categories: Entry Controlled Loops: are loops in which condition to be tested is present in beginning of loop body. while loop and for loop are entry controlled loops. Exit Controlled Loops: are loops in which the testing condition is present at the end of loop body. do-while is an exit controlled loop. Note: In Exit Controlled Loops, loop body will be evaluated for at-least one time as the testing condition is present at the end of loop body.
  • 6. THEWHILE LOOP You will get a nice listing of numbers, from 0 to 4. The number is first defined as 0, and each time the code in the loop is executed, it's incremented by one. class Program { static void Main(string[] args) { int number = 0; while(number < 5) { Console.WriteLine(number); number = number + 1; } Console.ReadLine(); } } The while loop simply executes a block of code as long as the condition you give it is true.
  • 7. THE WHILE LOOP Now print your name 20 times using while loop
  • 8. THE FOR LOOP This produces the exact same output, but as you can see, the for loop is a bit more compact. It consists of 3 parts - we initialize a variable for counting, set up a conditional statement to test it, and increment the counter class Program { static void Main(string[] args) { int number = 5; for(int i = 0; i < number; i++) Console.WriteLine(i); } } The for loop is a bit different. It's preferred when you know how many iterations you want, either because you know the exact amount of iterations, or because you have a variable containing the amount.
  • 9. THE DO-WHILE LOOP The output is the same though - once the number is more than 5, the loop is exited. class Program { static void Main(string[] args) { int number = 0; do { Console.WriteLine(number); number = number + 1; } while(number < 5); } } do while loop is similar to while loop with only difference that it checks the condition after executing the statements, i.e it will execute the loop body one time for sure because it checks the condition after executing the statements.
  • 10. ASSIGNMENT 1. Write a program in C# Sharp to display the multiplication table of a given integer 2. Write a C# Sharp program to calculate the factorial of a given number 3. Write a program in C# Sharp to read 10 numbers from keyboard and find their sum and average 4. Write a C# program that converts feet to meters.The program should display feet from 3 to 30 in three-foot increments and the corresponding meter equivalents. Use the relationship of 3.28 feet to a meter. 5. Write a C# Sharp program to find the sum of first 10 odd numbers.
  • 11. REFERENCES • Visual C# How to Program (6th Edition) (Deitel Series) • https://www.geeksforgeeks.org/loops-in-c-sharp/ • https://csharp.net-tutorials.com/control-structures/loops/