SlideShare ist ein Scribd-Unternehmen logo
1 von 2
(TCO 5) Describe two types of loops that can be used to write the C# code required to print
every second integer from 1 to 201 (i.e., 1, 3, 5, 7, etc.), each on its own line. Which would be a
better choice and why? Write the code using that type of loop. (Points : 20)
Solution
A loop statement allows us to execute a statement or a group of statements multiple times
while loop
It repeats a statement or a group of statements while a given condition is true. It tests the
condition before executing the loop body.
for loop
It executes a sequence of statements multiple times and abbreviates the code that manages the
loop variable.
using System;
namespace Loops
{
class Program
{
static void Main(string[] args)
{
}
}
}
In c# the for loop is slightly faster
For loop average about 2.95 to 3.02 sec
The while loop averages about 3.05 70 3.37 ms

Weitere ähnliche Inhalte

Ähnlich wie (TCO 5) Describe two types of loops that can be used to write the C# c.docx

Ähnlich wie (TCO 5) Describe two types of loops that can be used to write the C# c.docx (20)

Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Ecma script
Ecma scriptEcma script
Ecma script
 
C# note
C# noteC# note
C# note
 
The Loops
The LoopsThe Loops
The Loops
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdf
 
IFSM 310 Software and Hardware Infrastructure ConceptsComputer.docx
IFSM 310 Software and Hardware Infrastructure ConceptsComputer.docxIFSM 310 Software and Hardware Infrastructure ConceptsComputer.docx
IFSM 310 Software and Hardware Infrastructure ConceptsComputer.docx
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
 
C loops
C loopsC loops
C loops
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Parllelizaion
ParllelizaionParllelizaion
Parllelizaion
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
 
Unix day3 v1.3
Unix day3 v1.3Unix day3 v1.3
Unix day3 v1.3
 
LOOPS IN C.pptx
LOOPS IN C.pptxLOOPS IN C.pptx
LOOPS IN C.pptx
 
While and For Loops
While and For LoopsWhile and For Loops
While and For Loops
 
Bansal presentation (1).pptx
Bansal presentation (1).pptxBansal presentation (1).pptx
Bansal presentation (1).pptx
 

Mehr von pjoseph6

-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx
-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx
-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docxpjoseph6
 
(Multiple choice) Which one of the following statements is true- Expla.docx
(Multiple choice) Which one of the following statements is true- Expla.docx(Multiple choice) Which one of the following statements is true- Expla.docx
(Multiple choice) Which one of the following statements is true- Expla.docxpjoseph6
 
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docxpjoseph6
 
- What is continuous linked settlement and how does it operate- - What.docx
- What is continuous linked settlement and how does it operate- - What.docx- What is continuous linked settlement and how does it operate- - What.docx
- What is continuous linked settlement and how does it operate- - What.docxpjoseph6
 
- What is a right-to-work state- What are the advantages or disadvanta.docx
- What is a right-to-work state- What are the advantages or disadvanta.docx- What is a right-to-work state- What are the advantages or disadvanta.docx
- What is a right-to-work state- What are the advantages or disadvanta.docxpjoseph6
 
(b) Ionization energy generally increases from left to right across th.docx
(b) Ionization energy generally increases from left to right across th.docx(b) Ionization energy generally increases from left to right across th.docx
(b) Ionization energy generally increases from left to right across th.docxpjoseph6
 
- How are corporate hierarchies related to the systems concept-Solutio.docx
- How are corporate hierarchies related to the systems concept-Solutio.docx- How are corporate hierarchies related to the systems concept-Solutio.docx
- How are corporate hierarchies related to the systems concept-Solutio.docxpjoseph6
 
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docxpjoseph6
 
- Classify each of the following as a pure substance or a mixture- if.docx
- Classify each of the following as a pure substance or a mixture- if.docx- Classify each of the following as a pure substance or a mixture- if.docx
- Classify each of the following as a pure substance or a mixture- if.docxpjoseph6
 
- Below are nominal GDP and GDP deflators for four years- Calculate re.docx
- Below are nominal GDP and GDP deflators for four years- Calculate re.docx- Below are nominal GDP and GDP deflators for four years- Calculate re.docx
- Below are nominal GDP and GDP deflators for four years- Calculate re.docxpjoseph6
 

Mehr von pjoseph6 (10)

-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx
-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx
-- NaCIO- Bu4NHSO4 EtOAc (ethyl acetate) Benzophenone Benzhydrol Solut.docx
 
(Multiple choice) Which one of the following statements is true- Expla.docx
(Multiple choice) Which one of the following statements is true- Expla.docx(Multiple choice) Which one of the following statements is true- Expla.docx
(Multiple choice) Which one of the following statements is true- Expla.docx
 
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx
(Internal controls for plant assets) Harris- CPA- has accepted an enga.docx
 
- What is continuous linked settlement and how does it operate- - What.docx
- What is continuous linked settlement and how does it operate- - What.docx- What is continuous linked settlement and how does it operate- - What.docx
- What is continuous linked settlement and how does it operate- - What.docx
 
- What is a right-to-work state- What are the advantages or disadvanta.docx
- What is a right-to-work state- What are the advantages or disadvanta.docx- What is a right-to-work state- What are the advantages or disadvanta.docx
- What is a right-to-work state- What are the advantages or disadvanta.docx
 
(b) Ionization energy generally increases from left to right across th.docx
(b) Ionization energy generally increases from left to right across th.docx(b) Ionization energy generally increases from left to right across th.docx
(b) Ionization energy generally increases from left to right across th.docx
 
- How are corporate hierarchies related to the systems concept-Solutio.docx
- How are corporate hierarchies related to the systems concept-Solutio.docx- How are corporate hierarchies related to the systems concept-Solutio.docx
- How are corporate hierarchies related to the systems concept-Solutio.docx
 
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx
- Describe in one or two paragraphs what is Web (8-10 lines) Your desc.docx
 
- Classify each of the following as a pure substance or a mixture- if.docx
- Classify each of the following as a pure substance or a mixture- if.docx- Classify each of the following as a pure substance or a mixture- if.docx
- Classify each of the following as a pure substance or a mixture- if.docx
 
- Below are nominal GDP and GDP deflators for four years- Calculate re.docx
- Below are nominal GDP and GDP deflators for four years- Calculate re.docx- Below are nominal GDP and GDP deflators for four years- Calculate re.docx
- Below are nominal GDP and GDP deflators for four years- Calculate re.docx
 

Kürzlich hochgeladen

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
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
 

Kürzlich hochgeladen (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
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 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

(TCO 5) Describe two types of loops that can be used to write the C# c.docx

  • 1. (TCO 5) Describe two types of loops that can be used to write the C# code required to print every second integer from 1 to 201 (i.e., 1, 3, 5, 7, etc.), each on its own line. Which would be a better choice and why? Write the code using that type of loop. (Points : 20) Solution A loop statement allows us to execute a statement or a group of statements multiple times while loop It repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body. for loop It executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. using System; namespace Loops { class Program { static void Main(string[] args) { } }
  • 2. } In c# the for loop is slightly faster For loop average about 2.95 to 3.02 sec The while loop averages about 3.05 70 3.37 ms