For Loops
are an example of syntactic sugar
1) how do i start?
2) how do i end?
3) step
For i = 1 to 10
ListBox1.Items.Add(i*i)
Next
When should I use a For loop?
1) you want to do something a fixed number of times
(In this instance, i don't *use* the variable i inside the loop at all)
2) when you want to generate a series of numbers
ex 1:
Dim year as Integer
pop = 300000
For year = 2006 To 2010
LstTable.Items.Add(year & " " & pop)
pop = pop + pop * 0.03
Next
Alternatively:
pop = 300000
For year as integer = 2006 To 2010
LstTable.Items.Add(year & " " & pop)
pop = pop + pop * 0.03
Next
if I have:
x operator= 6
x = x operator 6
for loops, 30-40 even
row = ""
for i = 1 to 10
row = row & "*"
next
for i = 1 to 10
listbox1.items.add(row)
next
for i = 1 to 10
row = ""
for i = 1 to 10
row = row & "*"
next
listbox1.items.add(row)
next
No comments:
Post a Comment