SlideShare a Scribd company logo
1 of 29
Introducing the Do While…Loop
and Do Until…Loop Repetition
Statements
Introducing the Do…Loop While
and Do…Loop Until Repetition
Statements
Do While…Loop Repetition
Statement
• Loop-continuation condition
– While loop-continuation condition remains
true, loop statement executes its body
repeatedly
– When loop-continuation condition becomes
false, loop terminates
• Code example:
– Dim intProduct As Integer = 3
Do While intProduct <= 50
intProduct *= 3
Loop
Do While…Loop Repetition
Statement
[intProduct <= 50]
[intProduct > 50]
triple product value
merge
decision
Corresponding Visual Basic .NET
statement:
intProduct *= 3
Figure 9.4   Do While Loop repetition statement UML activity diagram.
Do Until…Loop Repetition
Statement
• Loop-continuation condition
– While loop-continuation condition remains
false, loop statement executes its body
repeatedly
– When loop-continuation condition becomes
true, loop terminates
• Code example:
– Dim intProduct As Integer = 3
Do Until intProduct > 50
intProduct *= 3
Loop
Do Until…Loop Repetition
Statement
[intProduct <= 50]
[intProduct > 50]
triple product value
merge
decision
Corresponding Visual Basic .NET
statement:
intProduct *= 3
Figure 9.5   Do Until Loop repetition statement UML activity diagram
Do…Loop While Repetition
Statement
• Do…Loop While example:
Dim intCouner As Integer = 1
Do
1stDisplay/Items.Add(intCounter)
intCounter += 1
Loop While intCounter <= 3
• Set counter to 1
– Excecute body of Do…Loop While statement
while the counter is less than or equal to 3
Do…Loop While Repetition
Statement
decision
action state
[intCounter <= 3]
[intCounter > 3]
Corresponding VB .NET Statements:
lstDisplay.Items.Add(intCounter)
intCounter += 1
loop-
continuation
condition
  Do…Loop While repetition statement UML activity diagram.
• Do…Loop While repetition statement
– Body of the loop executes first
– Loop-continuation condition checked
• If False, loop exits
• If True, loop executes again
Do…Loop Until Repetition
Statement
• Do…Loop Until example:
Dim intCouner As Integer = 1
Do
1stDisplay/Items.Add(intCounter)
intCounter += 1
Loop Until intCounter > =3
• Set counter to 1
– Execute body of Do…Loop Until statement until the
counter is greater than to 3
Do…Loop Until Repetition
Statement
Decision
action state
[intCounter <= 3]
[intCounter > 3]
Corresponding VB .NET Statements:
lstDisplay.Items.Add(intCounter)
intCounter += 1
Loop-
termination
condition
  Do…Loop Until repetition statement UML activity diagram.
• Do…Loop Until repetition statement
– Body of the loop executes
– Loop-continuation condition checked
• If False, loop executes again
• If True, loop exits
Introducing the Do…Loop While
and Do…Loop Until Repetition
Statements
Class Average Application
Test-Driving the Class Average
Application
Application Requirements
A teacher regularly issues quizzes to a class of ten students. The grades on these
quizzes are integers in the range from 0 to 100 (0 and 100 are each valid grades).
The teacher would like you to develop an application that computes the class
average for a quiz.
Test-Driving the Class Average
Application
  Entering grades in the Class Average application.
• Entering quiz grades
– Enter a grade into the Enter grade: TextBox
– Click Add Grade Button
– Grade added to ListBox
– Focus given to TextBox
Test-Driving the Class Average
Application
Figure 10.3   Class Average application after 10 grades have been
input.
Ten quiz grades entered Disabled Add Grade Button
• Entering ten grades
– Add Grade Button disabled
– Click Average Button to calculate average quiz grade
Test-Driving the Class Average
Application
Figure 10.4   Displaying the class average.
Label displaying average
Click to calculate class average
• Calculating the average
– Click the Average Button
– Average displayed in output Label
– Add Grade Button enabled
Test-Driving the Class Average
Application
Figure 10.5   Entering a new set of grades.
• Entering another set of grades
– Old quiz grades removed from ListBox
– New grade added to ListBox
Creating the Class Average
Application
Event Control Event
Label all the application’s controls lblPrompt, lblGradeList,
lblDescribeOutput
User enters grade txtInput
Retrieve grade entered by user in the Enter
grade: TextBox
btnAdd Click
Display the grades lstGrades
Calculate the class average by reading ListBox
values
btnAverage Click
Display the class average lblOutput
  ACE table for the Class Average application.
Creating the Class Average
Application
Class Average application’s Form in design view.
• Template application
– Contains:
• ListBox
• Buttons
• Output Label
18
Creating the Class Average
Application
  Clearing the ListBox and output Label after a calculation.
Clearing the grade
list and class average
• Clearing ListBox and output Label
– If output Label contains text
• Clear output Label of previous result
• Clear ListBox of previous quiz grades
19
Creating the Class Average
Application
Adding the grade input to the ListBox and clearing the Enter grade:
TextBox.
• Displaying grades
– Add grade to ListBox
– Clear TextBox txtInput
Adding a numeric grade
to the ListBox and
clearing the user input
from the TextBox
20
Creating the Class Average
Application
  Transferring the focus to the TextBox control.
Transferring the focus
of the application to
the TextBox
• Transferring focus to a control
– Makes application easier to user
– Use method Focus of that control
21
Creating the Class Average
Application
• Accepting ten grades
– Use method lstGrades.Items.Count to determine if ten grades
entered
– If ten grades entered:
• Disable Add Grade Button
• Give focus to Average Button
22
Creating the Class Average
Application
  Application accepts only 10 grades.
Disabling the Add
grade Button
and transferring
the focus to the
Average Button
23
Creating the Class Average
Application
Do…Loop Until summing grades.
Using the Do…Loop
Until repetition
statement to sum
grades in the ListBox.
24
Creating the Class Average
Application
• Adding quiz grades
– Use a Do…Loop Until statement to retrieve ten grades
• Use lstGrades.Items.Item() to retrieve grade from
ListBox
• Add grade to intTotal
• Increment counter
25
Creating the Class Average
Application
• Displaying average
– Calculate average of ten quiz grades
– Format and display average
– Enable Add Grade Button
– Transfer the focus to txtInput TextBox
26
Creating the Class Average
Application
  Displaying the result of the average calculation.
Calculating the
class average,
enabling the Add
Grade Button, and
transferring the
focus to the Enter
Grade: TextBox.
27
ClassAverage.vb
(1 of 3)
1 Public Class FrmClassAverage
2 Inherits System.Windows.Forms.Form
3
4 ' Windows Form Designer generated code
5
6 ' handles Add Grade Button’s Click event
7 Private Sub btnAdd_Click(ByVal sender As System.Object, _
8 ByVal e As System.EventArgs) Handles btnAdd.Click
9
10 ' clear previous grades and calculation result
11 If lblOutput.Text <> ““ Then
12 lblOutput.Text = ““
13 lstGrades.Items.Clear()
14 End If
15
16 ' display grade in ListBox
17 lstGrades.Items.Add(Val(txtInput.Text))
18 txtInput.Clear() ' clear grade from TextBox
19 txtInput.Focus() ' transfer focus to TextBox
20
21 ' prohibit users from entering more than 10 grades
22 If lstGrades.Items.Count >= 10 Then
23 btnAdd.Enabled = False ' disable Add Grade Button
24 btnAverage.Focus() ' transfer focus to Average
Button
25 End If
Disabling the Add Grade Button and
transferring the focus to the Average
Button
28
ClassAverage.vb
(2 of 3)
26
27 End Sub ' btnAdd_Click
28
29 ' handles Average Button’s Click event
30 Private Sub btnAverage_Click(ByVal sender As System.Object, _
31 ByVal e As System.EventArgs) Handles btnAverage.Click
32
33 ' initialization phase
34 Dim intTotal As Integer = 0
35 Dim intGradeCounter As Integer = 0
36 Dim intGrade As Integer = 0
37 Dim dblAverage As Double = 0
38
39 ' sum grades in ListBox
40 Do
41
42 ' read grade from ListBox
43 intGrade = lstGrades.Items.Item(intGradeCounter)
44 intTotal += intGrade ' add grade to total
45 intGradeCounter += 1 ' increment counter
46 Loop Until intGradeCounter >= 10
47
Using a Do…Loop Until
statement to calculate the class
average
29
ClassAverage.vb
(3 of 3)
48 dblAverage = intTotal / 10 ' calculate average
49 lblOutput.Text = String.Format(“{0:F}”, dblAverage)
50 btnAdd.Enabled = True ' enable Add Grade Button
51 txtInput.Focus() ' reset focus to Enter grade: TextBox
52 End Sub ' btnAverage_Click
53
54 End Class ' FrmClassAverage
Enabling the Add
Grade Button and
transferring the focus
to the Enter grade:
TextBox

More Related Content

Similar to Do While and Do Until Loops in VB.NET Class Average App

Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptxKrishanthaRanaweera1
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Blue Elephant Consulting
 
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxCMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxclarebernice
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Seleniumelliando dias
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxAASTHA76
 
control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)Prashant Sharma
 
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docxPT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docxamrit47
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Alpro
 
Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0PMILebanonChapter
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfenodani2008
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseAlexandra N. Martinez
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobCiaranMcNulty
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptSuleman Khan
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth hammad ali
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test communityKerry Buckley
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0Vishy Chandra
 

Similar to Do While and Do Until Loops in VB.NET Class Average App (20)

Advanced Computer Programming..pptx
Advanced Computer Programming..pptxAdvanced Computer Programming..pptx
Advanced Computer Programming..pptx
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
 
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxCMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 
control statements of clangauge (ii unit)
control statements of clangauge (ii unit)control statements of clangauge (ii unit)
control statements of clangauge (ii unit)
 
Visual programming
Visual programmingVisual programming
Visual programming
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docxPT1420 Decision Structures in Pseudocode and Visual Basic .docx
PT1420 Decision Structures in Pseudocode and Visual Basic .docx
 
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
Computer paper 3 may june 2004 9691 cambridge General Certificate of educatio...
 
Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
 
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-caseToronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
Toronto Virtual Meetup #11 - Reviewing Complex DataWeave Transformation Use-case
 
Finding the Right Testing Tool for the Job
Finding the Right Testing Tool for the JobFinding the Right Testing Tool for the Job
Finding the Right Testing Tool for the Job
 
cpphtp4_PPT_02.ppt
cpphtp4_PPT_02.pptcpphtp4_PPT_02.ppt
cpphtp4_PPT_02.ppt
 
more loops lecture by Professor Evan korth
more loops  lecture by Professor Evan korth more loops  lecture by Professor Evan korth
more loops lecture by Professor Evan korth
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0
 

Recently uploaded

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
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
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
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
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
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
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
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
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
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
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

Do While and Do Until Loops in VB.NET Class Average App

  • 1. Introducing the Do While…Loop and Do Until…Loop Repetition Statements Introducing the Do…Loop While and Do…Loop Until Repetition Statements
  • 2. Do While…Loop Repetition Statement • Loop-continuation condition – While loop-continuation condition remains true, loop statement executes its body repeatedly – When loop-continuation condition becomes false, loop terminates • Code example: – Dim intProduct As Integer = 3 Do While intProduct <= 50 intProduct *= 3 Loop
  • 3. Do While…Loop Repetition Statement [intProduct <= 50] [intProduct > 50] triple product value merge decision Corresponding Visual Basic .NET statement: intProduct *= 3 Figure 9.4   Do While Loop repetition statement UML activity diagram.
  • 4. Do Until…Loop Repetition Statement • Loop-continuation condition – While loop-continuation condition remains false, loop statement executes its body repeatedly – When loop-continuation condition becomes true, loop terminates • Code example: – Dim intProduct As Integer = 3 Do Until intProduct > 50 intProduct *= 3 Loop
  • 5. Do Until…Loop Repetition Statement [intProduct <= 50] [intProduct > 50] triple product value merge decision Corresponding Visual Basic .NET statement: intProduct *= 3 Figure 9.5   Do Until Loop repetition statement UML activity diagram
  • 6. Do…Loop While Repetition Statement • Do…Loop While example: Dim intCouner As Integer = 1 Do 1stDisplay/Items.Add(intCounter) intCounter += 1 Loop While intCounter <= 3 • Set counter to 1 – Excecute body of Do…Loop While statement while the counter is less than or equal to 3
  • 7. Do…Loop While Repetition Statement decision action state [intCounter <= 3] [intCounter > 3] Corresponding VB .NET Statements: lstDisplay.Items.Add(intCounter) intCounter += 1 loop- continuation condition   Do…Loop While repetition statement UML activity diagram. • Do…Loop While repetition statement – Body of the loop executes first – Loop-continuation condition checked • If False, loop exits • If True, loop executes again
  • 8. Do…Loop Until Repetition Statement • Do…Loop Until example: Dim intCouner As Integer = 1 Do 1stDisplay/Items.Add(intCounter) intCounter += 1 Loop Until intCounter > =3 • Set counter to 1 – Execute body of Do…Loop Until statement until the counter is greater than to 3
  • 9. Do…Loop Until Repetition Statement Decision action state [intCounter <= 3] [intCounter > 3] Corresponding VB .NET Statements: lstDisplay.Items.Add(intCounter) intCounter += 1 Loop- termination condition   Do…Loop Until repetition statement UML activity diagram. • Do…Loop Until repetition statement – Body of the loop executes – Loop-continuation condition checked • If False, loop executes again • If True, loop exits
  • 10. Introducing the Do…Loop While and Do…Loop Until Repetition Statements Class Average Application
  • 11. Test-Driving the Class Average Application Application Requirements A teacher regularly issues quizzes to a class of ten students. The grades on these quizzes are integers in the range from 0 to 100 (0 and 100 are each valid grades). The teacher would like you to develop an application that computes the class average for a quiz.
  • 12. Test-Driving the Class Average Application   Entering grades in the Class Average application. • Entering quiz grades – Enter a grade into the Enter grade: TextBox – Click Add Grade Button – Grade added to ListBox – Focus given to TextBox
  • 13. Test-Driving the Class Average Application Figure 10.3   Class Average application after 10 grades have been input. Ten quiz grades entered Disabled Add Grade Button • Entering ten grades – Add Grade Button disabled – Click Average Button to calculate average quiz grade
  • 14. Test-Driving the Class Average Application Figure 10.4   Displaying the class average. Label displaying average Click to calculate class average • Calculating the average – Click the Average Button – Average displayed in output Label – Add Grade Button enabled
  • 15. Test-Driving the Class Average Application Figure 10.5   Entering a new set of grades. • Entering another set of grades – Old quiz grades removed from ListBox – New grade added to ListBox
  • 16. Creating the Class Average Application Event Control Event Label all the application’s controls lblPrompt, lblGradeList, lblDescribeOutput User enters grade txtInput Retrieve grade entered by user in the Enter grade: TextBox btnAdd Click Display the grades lstGrades Calculate the class average by reading ListBox values btnAverage Click Display the class average lblOutput   ACE table for the Class Average application.
  • 17. Creating the Class Average Application Class Average application’s Form in design view. • Template application – Contains: • ListBox • Buttons • Output Label
  • 18. 18 Creating the Class Average Application   Clearing the ListBox and output Label after a calculation. Clearing the grade list and class average • Clearing ListBox and output Label – If output Label contains text • Clear output Label of previous result • Clear ListBox of previous quiz grades
  • 19. 19 Creating the Class Average Application Adding the grade input to the ListBox and clearing the Enter grade: TextBox. • Displaying grades – Add grade to ListBox – Clear TextBox txtInput Adding a numeric grade to the ListBox and clearing the user input from the TextBox
  • 20. 20 Creating the Class Average Application   Transferring the focus to the TextBox control. Transferring the focus of the application to the TextBox • Transferring focus to a control – Makes application easier to user – Use method Focus of that control
  • 21. 21 Creating the Class Average Application • Accepting ten grades – Use method lstGrades.Items.Count to determine if ten grades entered – If ten grades entered: • Disable Add Grade Button • Give focus to Average Button
  • 22. 22 Creating the Class Average Application   Application accepts only 10 grades. Disabling the Add grade Button and transferring the focus to the Average Button
  • 23. 23 Creating the Class Average Application Do…Loop Until summing grades. Using the Do…Loop Until repetition statement to sum grades in the ListBox.
  • 24. 24 Creating the Class Average Application • Adding quiz grades – Use a Do…Loop Until statement to retrieve ten grades • Use lstGrades.Items.Item() to retrieve grade from ListBox • Add grade to intTotal • Increment counter
  • 25. 25 Creating the Class Average Application • Displaying average – Calculate average of ten quiz grades – Format and display average – Enable Add Grade Button – Transfer the focus to txtInput TextBox
  • 26. 26 Creating the Class Average Application   Displaying the result of the average calculation. Calculating the class average, enabling the Add Grade Button, and transferring the focus to the Enter Grade: TextBox.
  • 27. 27 ClassAverage.vb (1 of 3) 1 Public Class FrmClassAverage 2 Inherits System.Windows.Forms.Form 3 4 ' Windows Form Designer generated code 5 6 ' handles Add Grade Button’s Click event 7 Private Sub btnAdd_Click(ByVal sender As System.Object, _ 8 ByVal e As System.EventArgs) Handles btnAdd.Click 9 10 ' clear previous grades and calculation result 11 If lblOutput.Text <> ““ Then 12 lblOutput.Text = ““ 13 lstGrades.Items.Clear() 14 End If 15 16 ' display grade in ListBox 17 lstGrades.Items.Add(Val(txtInput.Text)) 18 txtInput.Clear() ' clear grade from TextBox 19 txtInput.Focus() ' transfer focus to TextBox 20 21 ' prohibit users from entering more than 10 grades 22 If lstGrades.Items.Count >= 10 Then 23 btnAdd.Enabled = False ' disable Add Grade Button 24 btnAverage.Focus() ' transfer focus to Average Button 25 End If Disabling the Add Grade Button and transferring the focus to the Average Button
  • 28. 28 ClassAverage.vb (2 of 3) 26 27 End Sub ' btnAdd_Click 28 29 ' handles Average Button’s Click event 30 Private Sub btnAverage_Click(ByVal sender As System.Object, _ 31 ByVal e As System.EventArgs) Handles btnAverage.Click 32 33 ' initialization phase 34 Dim intTotal As Integer = 0 35 Dim intGradeCounter As Integer = 0 36 Dim intGrade As Integer = 0 37 Dim dblAverage As Double = 0 38 39 ' sum grades in ListBox 40 Do 41 42 ' read grade from ListBox 43 intGrade = lstGrades.Items.Item(intGradeCounter) 44 intTotal += intGrade ' add grade to total 45 intGradeCounter += 1 ' increment counter 46 Loop Until intGradeCounter >= 10 47 Using a Do…Loop Until statement to calculate the class average
  • 29. 29 ClassAverage.vb (3 of 3) 48 dblAverage = intTotal / 10 ' calculate average 49 lblOutput.Text = String.Format(“{0:F}”, dblAverage) 50 btnAdd.Enabled = True ' enable Add Grade Button 51 txtInput.Focus() ' reset focus to Enter grade: TextBox 52 End Sub ' btnAverage_Click 53 54 End Class ' FrmClassAverage Enabling the Add Grade Button and transferring the focus to the Enter grade: TextBox