30/10/20151 3.4 iteration loops do while (condition is true) … loop

36
18/06/22 18/06/22 1 3.4 Iteration 3.4 Iteration Loops Loops Do While Do While (condition is true) (condition is true) Loop Loop

Upload: trevor-oliver

Post on 04-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

20/04/2320/04/23 11

3.4 Iteration Loops3.4 Iteration Loops

Do WhileDo While (condition is true)(condition is true) … … LoopLoop

Page 2: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

2220/04/2320/04/23

Learning ObjectivesLearning ObjectivesState when the State when the Do WhileDo While (condition is true)(condition is true) … … Loop Loop should be should be used.used.State the general form of the State the general form of the Do WhileDo While (condition is true)(condition is true) … … LoopLoop..State when State when Do WhileDo While (condition is true)(condition is true) … … Loop Loop will be will be executed.executed.State when State when Do WhileDo While (condition is true)(condition is true) … … Loop Loop will be exited.will be exited.State and explain the difference between State and explain the difference between Do WhileDo While (condition (condition is true)is true) … … Loop Loop andand Do Do … … Loop Until Loop Until (condition is true).(condition is true).Explain what the Explain what the RoundRound and and RandomRandom functions do and how to use functions do and how to use them.them.Setting an initial value of a variable when it is declared.Setting an initial value of a variable when it is declared.Explain how to “reset” by returning variables to their initial states / Explain how to “reset” by returning variables to their initial states / default values.default values.

Page 3: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

3320/04/2320/04/23

Dim Number As IntegerDim Number As IntegerNumber = 5Number = 5DoDo

Console.WriteLine(Number*Number)Console.WriteLine(Number*Number) Number = Number + 1Number = Number + 1

Loop Until Number = 10Loop Until Number = 10

The code above will produce:The code above will produce: 2525 3636 4949 6464 8181

Page 4: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Do WhileDo While (condition is true)(condition is true) … … LoopLoop

Is a “Is a “pre-conditionpre-condition” loop.” loop.

Page 5: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

5520/04/2320/04/23

Differences BetweenDifferences Between ““Do …. Loop …. UntilDo …. Loop …. Until” ”

& & ““Do While …. LoopDo While …. Loop””

Iteration LoopsIteration Loops

Page 6: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

6620/04/2320/04/23

Dim Number As IntegerDim Number As Integer

Number = 5Number = 5

DoDo

Console.WriteLine(Number*Number)Console.WriteLine(Number*Number)

Number = Number + 1Number = Number + 1

Loop Until Number = 10Loop Until Number = 10

Dim Number As IntegerDim Number As IntegerNumber = 5Number = 5Do Do While Number <= While Number <= 99

Console.WriteLine(Number*Number)Console.WriteLine(Number*Number)Number = Number + 1Number = Number + 1

LoopLoop

The end is now simply Loop. The end is now simply Loop.

1. The1. The focus is now on focus is now on when to start or continuewhen to start or continue rather than rather than when to end. when to end.

2.2. So the end point So the end point is reversed into a is reversed into a when to start or continue when to start or continue conditioncondition and is placed at the and is placed at the beginningbeginning of the loop of the loop rather rather than at the end.than at the end.

3.3. Note that this means that the “start/continue” point is lowered Note that this means that the “start/continue” point is lowered (comparable to the end point of a “For …. To …. Next” loop).(comparable to the end point of a “For …. To …. Next” loop).

Page 7: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

7720/04/2320/04/23

Dim Number As IntegerDim Number As Integer

Number = 5Number = 5

Do While Number <= 9Do While Number <= 9lstNumber.Items.Add(Number*Number)lstNumber.Items.Add(Number*Number)

Number = Number + 1Number = Number + 1

LoopLoop

Dim Number As IntegerDim Number As Integer

For Number = 5 To 9For Number = 5 To 9

lstNumber.Items.Add(Number*Number)lstNumber.Items.Add(Number*Number)

Next NumberNext Number

StartStart

Number is Number is

automatically incremented in a “For …To … Next” loop automatically incremented in a “For …To … Next” loop

but not in a “Do While …. Loop” loop.but not in a “Do While …. Loop” loop.

Differences BetweenDifferences Between

““For …. To …. NextFor …. To …. Next””

& & ““Do While …. LoopDo While …. Loop””

LoopsLoops

Page 8: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

8820/04/2320/04/23

Start / End Point Issue Start / End Point Issue

Note that the line to increment:Note that the line to increment: Number = Number + 1Number = Number + 1

Could be placed at the beginning of a “Do While … Could be placed at the beginning of a “Do While … Loop” loop. This would lower the “when to start or Loop” loop. This would lower the “when to start or continue” condition and lower the “start” value.continue” condition and lower the “start” value.Dim Number As IntegerDim Number As IntegerNumber = Number = 44Do Do While Number <= While Number <= 88

Number = Number + 1 Number = Number + 1 Console.WriteLine(Number*Number)Console.WriteLine(Number*Number)

LoopLoop

Page 9: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

9920/04/2320/04/23

Do WhileDo While (condition is true)(condition is true) … … LoopLoop

Used if there is a possibility that the loop Used if there is a possibility that the loop body statements should not be executed.body statements should not be executed.

Runs as long as the boolean condition in Runs as long as the boolean condition in the first line of the loop is true, otherwise it the first line of the loop is true, otherwise it exits.exits. i.e. it will be exited when the Boolean i.e. it will be exited when the Boolean

condition in the first line becomes false.condition in the first line becomes false.

Page 10: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

101020/04/2320/04/23

General Form of a General Form of a Do WhileDo While (condition is true)(condition is true) … … LoopLoopDo While (condition is true)Do While (condition is true) Loop body statementsLoop body statements

Loop Loop

Since the condition is set at the beginning Since the condition is set at the beginning of the loop the loop body may not be of the loop the loop body may not be executed at all i.e. skipped.executed at all i.e. skipped.This feature distinguishes it from the This feature distinguishes it from the Do Do … … Loop Until Loop Until (condition is true).(condition is true).

Page 11: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

111120/04/2320/04/23

Setting an initial value of a variable Setting an initial value of a variable when it is declared.when it is declared.

Dim Dim …… As As …… = = … … Can be used to set an initial value of a Can be used to set an initial value of a

variable when it is declared.variable when it is declared.

Page 12: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

121220/04/2320/04/23

Program 3.4a Password Entry 2Program 3.4a Password Entry 2

Specification:Specification: Same as Same as 3.3a Password Entry but: but:

Use Do While … Loop.Use Do While … Loop.

Page 13: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Replace the lines beginning and ending the Replace the lines beginning and ending the loop with:loop with:

‘‘Allow the user to enter a password as long as they haven’tAllow the user to enter a password as long as they haven’t ‘‘already had 3 attempts.already had 3 attempts. Do While Attempt < 3 And PasswordAttempt <> PasswordDo While Attempt < 3 And PasswordAttempt <> Password

And Cancel <> FalseAnd Cancel <> False…………....…………....…………....

Loop Loop ‘Signifies the end of the loop.‘Signifies the end of the loop.

Go to next slide.Go to next slide.

131320/04/2320/04/23

Program 3.4a Password Entry 2Program 3.4a Password Entry 2

Page 14: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

141420/04/2320/04/23

Program 3.4a Password Entry 2Program 3.4a Password Entry 2You will now notice a green squiggly line underneath You will now notice a green squiggly line underneath PasswordAttempt in the line:PasswordAttempt in the line:

Do While Attempt < 3 And PasswordAttempt <> PasswordDo While Attempt < 3 And PasswordAttempt <> Password

Hover over and read the error message that pops up.Hover over and read the error message that pops up.VB is warning you that you are testing the value of the VB is warning you that you are testing the value of the AttemptPasswordAttemptPassword variable before it has been set a value. variable before it has been set a value.Actually this is just a warning and will not usually cause Actually this is just a warning and will not usually cause problems.problems.However, it is good programming practice to solve it by However, it is good programming practice to solve it by setting a value when the variable is declared:setting a value when the variable is declared:

Change the line:Change the line:Dim PasswordAttempt AsDim PasswordAttempt As String String

to:to:To set a value to the PassWordAttempt variable so the variable is not tested before To set a value to the PassWordAttempt variable so the variable is not tested before it has a valueit has a value

Dim PasswordAttempt As StringDim PasswordAttempt As String = “ “ = “ “‘.‘.

Page 15: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

151520/04/2320/04/23

Program 3.4a Password Entry 2Program 3.4a Password Entry 2

Run the program and test it.Run the program and test it.

Page 16: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

161620/04/2320/04/23

Extension 3.4a Password Entry 2Extension 3.4a Password Entry 2

Extend the program so that:Extend the program so that: If Attempt = 1 the program outputs “First try is If Attempt = 1 the program outputs “First try is

wrong. Please try again”.wrong. Please try again”. On the second try the program outputs On the second try the program outputs

“Password still wrong. One more chance”.“Password still wrong. One more chance”. On the third try the program outputs “No valid On the third try the program outputs “No valid

password entered”.password entered”.

Page 17: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Given pseudocode will use the following structure:

WHILE <condition> <statement(s)>

ENDWHILE

Page 18: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

181820/04/2320/04/23

Extension 3.4bExtension 3.4b

Change one of the “For …. To …. Next” loop programs Change one of the “For …. To …. Next” loop programs you have written in you have written in 3.1 or or 3.2 Loops Loops to use a: to use a: Do While Do While (condition is true)(condition is true) … Loop … Loop

instead.instead.

With the incrementing line at the end of the loopWith the incrementing line at the end of the loop, immediately , immediately beforebefore Loop Loop e.g.e.g.

Do While Index ….Do While Index ….………………IndexIndex = = IndexIndex + 1 + 1

LoopLoop

Make a copy of the previous program’s whole folder to keep the original program but Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add rename this folder with the same name but add ((Do While … Loop VersionDo While … Loop Version))..

Page 19: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

191920/04/2320/04/23

Extension 3.4cExtension 3.4c

Change one of the “For …. To …. Next” loop programs Change one of the “For …. To …. Next” loop programs you have written in you have written in 3.1 or 3 or 3.2 Loops.2 Loops to use a: to use a: Do While Do While (condition is true)(condition is true) … Loop … Loop

instead.instead.

With the incrementing line at the beginning of the loopWith the incrementing line at the beginning of the loop, immediately , immediately afterafter Do ….Do …. e.g. e.g.

Do While Index ….Do While Index ….IndexIndex = = IndexIndex + 1 + 1………………

LoopLoop

Make a copy of the previous program’s whole folder to keep the original program but Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add rename this folder with the same name but add ((Do While … Loop VersionDo While … Loop Version))..

Page 20: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

202020/04/2320/04/23

Extension 3.4dExtension 3.4d

Change the “Change the “Do … Loop Until (condition is true)Do … Loop Until (condition is true)” ” loop program you changed in 3loop program you changed in 3.3 Loops.3 Loops to use to use a:a: Do While Do While (condition is true)(condition is true) … Loop … Loop

instead.instead.

You changed it from a “For …. To …. Next” initially into a “You changed it from a “For …. To …. Next” initially into a “Do … Loop Until Do … Loop Until (condition is true)(condition is true)” in 3.3 Loops.” in 3.3 Loops.

Make a copy of the previous program’s whole folder to keep the Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add original program but rename this folder with the same name but add ((Do While … Loop VersionDo While … Loop Version))..

Page 21: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

212120/04/2320/04/23

Extension 3.4eExtension 3.4e

Change this Program 5.4 Password Entry Change this Program 5.4 Password Entry 2 program to use a 2 program to use a ““For …. To …. Next” LoopFor …. To …. Next” Loop

Make a copy of the previous program’s whole folder to keep the Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add original program but rename this folder with the same name but add ((For …. To …. Next VersionFor …. To …. Next Version))..

Page 22: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Extension Programs 3.4 f - j

Please feel free to use any of the 3 forms of loops you deem appropriate in the following extension programs.However, I do suggest you attempt to balance your use each of the 3 forms, so that you are confident in their use. For … To … Next Do … Loop Until Do While … Loop

Page 23: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

232320/04/2320/04/23

Extension “Running Total” Extension “Running Total” Program 3.4Program 3.4ff

Write a program to allow a user to enter a Write a program to allow a user to enter a series of numbers and see their running totalseries of numbers and see their running total as each is entered.as each is entered.

After each number is entered the user should After each number is entered the user should be asked if he/she wishes to “Continue”, “Stop” be asked if he/she wishes to “Continue”, “Stop” or “Reset” or “Reset” (start again from 0)(start again from 0)..

To reset you will need to set all variables to their To reset you will need to set all variables to their initial states / default values.initial states / default values.

See the next slide for help with this.See the next slide for help with this.

Page 24: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

242420/04/2320/04/23

Extension “Sports Tally” Program 3.4Extension “Sports Tally” Program 3.4gg

Rema surveys the students in her class to find out which is Rema surveys the students in her class to find out which is the most popular sport.the most popular sport.

She draws a tally chart:She draws a tally chart:

Rema plans to collect sport data from students in the whole Rema plans to collect sport data from students in the whole school. She designs a program to:school. She designs a program to:

input the number of the sport a student likes best (1, 2, 3 or 4)input the number of the sport a student likes best (1, 2, 3 or 4) repeatedly ask for input until the input is 0 (zero)repeatedly ask for input until the input is 0 (zero) keep a count of each choicekeep a count of each choice on completion of data entry, print out the results as a tally chart (as on completion of data entry, print out the results as a tally chart (as

shown above)shown above)

Write this program.Write this program.

Page 25: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Variables – Initial States / Default valuesVariables – Initial States / Default values

When variables are declared they are set up with an When variables are declared they are set up with an “initial state” / “default value”:“initial state” / “default value”:

2525

Data Types Initial State / Default ValueByte / Integer / Decimal 0

String / Char “” (blank / empty / null)

Boolean False

Date / Time Nothing

Page 26: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

262620/04/2320/04/23

Round Round functionfunction

Used for rounding numbers and currency.Used for rounding numbers and currency.

Needs two arguments.Needs two arguments. Variable or constant to be formatted.Variable or constant to be formatted. The number of decimal places to be rounded to.The number of decimal places to be rounded to. Needs to be proceeded in VB by Math.Needs to be proceeded in VB by Math.

General Form:General Form:

Math.Round(Math.Round(VariableOrNumberToBeRoundedVariableOrNumberToBeRounded, , NumberOfDecimalPlacesToBeRoundedToNumberOfDecimalPlacesToBeRoundedTo))

Extension “Average” Program 3.4g Extension “Average” Program 3.4g

Page 27: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

272720/04/2320/04/23

Random Random functionfunction

Gives a random number between 0 and 1.Gives a random number between 0 and 1.

To generate whole numbers between 2 specified values:To generate whole numbers between 2 specified values: Randomize() Randomize() ' initialize the random-number generator.' initialize the random-number generator.

Note that without initialising, only one random will be generated per program run; so the Note that without initialising, only one random will be generated per program run; so the same random number will be used each time the Rnd() function is called, during that same random number will be used each time the Rnd() function is called, during that run.run.

Int(Rnd() * Int(Rnd() * HigherValueHigherValue ) + ) + LowerValueLowerValuee.g.e.g.

' To generate random value between 1 and 6. ' To generate random value between 1 and 6.

Int((Rnd())*6) + 1Int((Rnd())*6) + 1

Extension “Average” Program 3.4g Extension “Average” Program 3.4g

Page 28: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

2828

Extension “Average” Program 3.4h Extension “Average” Program 3.4h

Allow the user to enter as many exam marks as they wish.Allow the user to enter as many exam marks as they wish. After each mark is entered ask the user “Do you wish to calculate the After each mark is entered ask the user “Do you wish to calculate the

Average now? (True / False – means enter more numbers)”.Average now? (True / False – means enter more numbers)”.Use a Use a BooleanBoolean variable. variable.

Stops the user entering marks less than 0 and more than 100.Stops the user entering marks less than 0 and more than 100.

Then displays:Then displays: The highest and lowest marks.The highest and lowest marks.

See next 2 slides for some hints for this.See next 2 slides for some hints for this. The average mark rounded to 2 decimal places.The average mark rounded to 2 decimal places.

See slide 25.See slide 25.

Then asks the user if they wish to “Exit” or “Reset” Then asks the user if they wish to “Exit” or “Reset” (and start again)(and start again)..

Allow the user to use automatically generated random marks.Allow the user to use automatically generated random marks. See slide 26.See slide 26. Ask the user at the beginning whether they wish to enter marks or use randomly Ask the user at the beginning whether they wish to enter marks or use randomly

generated ones generated ones (if they do wish random numbers then also ask how many).(if they do wish random numbers then also ask how many).

Page 29: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Average – Highest & LowestAverage – Highest & Lowest

Possible Solution 1:As the marks have to be from 0 to 100 we can use these borderline values as the initial highest and lowest values respectively by setting:

Dim Lowest As Integer = 100 Dim Highest As Integer = 0

Make sure you include an explanation of these lines in your comments.

Each time a mark is entered, compare the newly entered mark with the variable Lowest (NewMark<Lowest). If it is lower then change the Lowest mark.

If NewMark < Lowest ThenLowest = NewMark

Do the same for Highest but in reverse. Remember to display the Lowest and Highest in appropriate labels.

When you comment on your If statements make sure you explain where you are testing and why does it have to be here, what you are testing for, why are you testing for this and what happens if the test is true.

Remember to edit the “Reset” button as well.

A second possible solution is on the next slide, I will leave you to decide which one you choose to actually use..A second possible solution is on the next slide, I will leave you to decide which one you choose to actually use..

Page 30: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Average – Highest & LowestAverage – Highest & LowestPossible Solution 2:

The first mark entered (butOK) could be stored in both the Lowest & Highest variables.

If NumberOfMarks = 1 ThenLowest = Highest = NewMark

You will then need to either position this new code at a certain place in the existing code or move the line which updates the NumberOfMarks (NumberOfMarks = NumberOfMarks + 1) to before you test for the first mark above or change how you test for the first mark.

Each time a mark is entered, compare the newly entered mark with the variable Lowest (NewMark<Lowest). If it is lower then change the Lowest mark.

If NewMark < Lowest ThenLowest = NewMark

Do the same for Highest but in reverse. Remember to display the Lowest and Highest in appropriate labels. When you comment on your If statements make sure you explain where

you are testing and why does it have to be here, what you are testing for, why are you testing for this and what happens if the test is true.

Remember to edit the “Reset” button as well.

I will leave you to decide which solution you choose to actually use.I will leave you to decide which solution you choose to actually use.

Page 31: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Extension “Conversion Ounces to Grams” Extension “Conversion Ounces to Grams” Program 3.4i Program 3.4i

Sheena has inherited a recipe book from her grandmother. All the Sheena has inherited a recipe book from her grandmother. All the recipes give ingredient measurements in ounces. Sheena wants to recipes give ingredient measurements in ounces. Sheena wants to write a program to produce a conversion table that helps her use the write a program to produce a conversion table that helps her use the correct weight in grams.correct weight in grams.

To convert ounces into grams: 1 ounce is 28.35 grams.To convert ounces into grams: 1 ounce is 28.35 grams.

The conversion table will show the number of grams to the nearest The conversion table will show the number of grams to the nearest whole number:whole number:

The built-in function ROUND(x) returns The built-in function ROUND(x) returns x rounded to the nearest whole number.x rounded to the nearest whole number.

Write a program to print the conversion table Write a program to print the conversion table for 1 to 16 ounces:for 1 to 16 ounces:

3131

Page 32: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

Extension “Number Guessing Game” Extension “Number Guessing Game” Program 3.4jProgram 3.4j

Raza wants to write a Raza wants to write a number-guessing number-guessing game. game.

He has drawn a He has drawn a flowchart of an flowchart of an algorithm:algorithm:

Write this program.Write this program.

3232

Page 33: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

333320/04/2320/04/23

PlenaryPlenary

When should the When should the Do WhileDo While (condition is true)(condition is true) … … Loop Loop be used?be used? Used if there is a possibility that the loop body Used if there is a possibility that the loop body

statements should not be executed.statements should not be executed.

So what is the minimum number of times a So what is the minimum number of times a Do Do WhileWhile (condition is true)(condition is true) … … LoopLoop may be executed? may be executed? 00

What is the general form of the What is the general form of the Do WhileDo While (condition is true)(condition is true) … … LoopLoop?? Do While (condition is true)Do While (condition is true)

Loop body statementsLoop body statements LoopLoop

Page 34: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

343420/04/2320/04/23

PlenaryPlenary

When will When will Do WhileDo While (condition is true)(condition is true) … … Loop Loop be executed?be executed? Runs as long as the Boolean condition in the Runs as long as the Boolean condition in the

first line of the loop is true, otherwise it exits.first line of the loop is true, otherwise it exits.

When will When will Do WhileDo While (condition is true)(condition is true) … … Loop Loop be exited?be exited? It will be exited when the Boolean condition in It will be exited when the Boolean condition in

the first line becomes false.the first line becomes false.

Page 35: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

353520/04/2320/04/23

PlenaryPlenary

State and explain the difference between State and explain the difference between Do Do WhileWhile (condition is true)(condition is true) … … Loop Loop andand Do Do … … Loop Loop Until Until (condition is true).(condition is true). The difference is that the loop body statements of a The difference is that the loop body statements of a

Do WhileDo While (condition is true)(condition is true) … … Loop Loop may not be may not be executed at all but aexecuted at all but a Do Do … … Loop Until Loop Until (condition is true) (condition is true) has to be executed at least once.has to be executed at least once.

This is because in a This is because in a Do WhileDo While (condition is true)(condition is true) … … Loop Loop the condition is at the beginning whereas in athe condition is at the beginning whereas in a Do Do … … Loop Until Loop Until (condition is true) (condition is true) the condition is at the the condition is at the end.end.

Page 36: 30/10/20151 3.4 Iteration Loops Do While (condition is true) … Loop

363620/04/2320/04/23

PlenaryPlenary

How do we set an initial value of a variable How do we set an initial value of a variable when it is declared.when it is declared. Dim Dim …… As As …… = = … …

Can be used to set an initial value of a variable Can be used to set an initial value of a variable when it is declared.when it is declared.