![]() |
Click here to advertise with us
|
|
|||||||
| VB.NET General Discussion VB.NET general discussion area |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi,
I just started learning VB.NET last night as I was told it's one of the best programming languages to begin learning for someone wanting to be a programmer. Anyway, I've been following up this tutorial which I've been doing quite well until today when I got up to For loops and I'm finding it hard to understand because it feels like my brain is going here, there, and everywhere. I'm not sure if it's me or if it's the tutorial that's making it confusing but I was wondering if somebody here could give me a hand? Ta for the help. |
|
||||
|
Programming does not exist in a vacuum. Programming concepts are pretty much all analogous to real world concepts. Consider an egg carton full of eggs. Assume that the cups are numbered from 0 to 11. Now, if I said to you, for a number i where i goes from 0 to 11, take egg number i and crack it into a bowl, you could do that, right? Congratulations! You just implemented a For loop.
A For loop has a loop control variable, also called a loop counter, that starts at a specific value and increments each iteration until it reaches a specific end value. Once the next iteration completes the loop ends. Within the loop you can use that loop control variable for whatever purpose is appropriate. The most common use is as an index into an array or collection, a la my egg carton example. That's not the only use though. Lets say that you wanted to sum all the numbers from 1 to 10. You could use a For loop where the loop control variable goes from 1 to 10 and in each iteration add the value of the loop control variable to a running total: Code:
Dim sum As Integer = 0
For i As Integer = 1 To 10
sum += i
Next
MessageBox.Show(sum.ToString(), "Sum")
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
|
||||
|
It depends what you mean by "best". VB.NET is easier for a rank beginner to pick up because the syntax is more natural and the fact that the language is less strict means you can learn the basic principles without having to worry about some of the details. That said, VB being less strict does provide it's own set of problems. "Best" is always a relative term. I think here it's being used as "easiest to learn the basics of", which is probably fairly accurate.
__________________
![]() 2007, 2008, 2009, 2010 Why is my data not saved to my database? | Communicating between multiple forms MSDN: Data Walkthroughs | "How Do I?" Videos My Blog: Custom Events | Dynamic GDI+ Drawing |
|
|||
|
Hey, thanks for your explanation. I think I'm understanding it a bit more now, but at first it was For loops in general I was having trouble understanding.
Are they usually a confusing subject to learn at first? And I've have only really touched Pascal and attempted Java before, and then heard that VB. NET was the best to learn if you have no previous history of this stuff, so I'm now giving VB .NET a try.
|
|
||||
|
Quote:
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
|
|||
|
Okay, thanks for the help.
I think I'm beginning to get it now.1. For i (name of loop's variable) 2. = 0 (where to begin from) 3. To *variable* (where to finish the loop and continue to next loop thereafter) 4. next i (loop again) So, 1 gives the name of the loop, 2 tells VB where to begin from, 3 tells VB where it has to loop to until required loops have finished, if required loops have finished it avoids 4 because it's done what it has to, if not then 4 tells VB to loop the variable again. Is that right? |
|
|||
|
It may be beneficial to take a look here: Loops in VB .NET - For Loop, While Loop, Do Loop
|
|
||||
|
Quote:
__________________
Some useful links: Learning videoes, Code Samples, WMI Code Creator, MSDN, The Code Project, WindowsClient.net, ASP.net, W3 Schools, Regular-Expressions.info, GDI+ FAQ
How to format posts with code blocks etc - present the problem/post properly ![]() |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|