Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT]Understanding the 'Do' Loop[TUT]

Understanding the 'Do' Loop


I have seen many members confused on how to use loops. Loops should be the first thing you should learn about any programming language as loops are important in every language. I am writing this tutorial explaining the Do Loop. Look for my other tutorials on the other loops.

Step One

Open a new Visual Basic Project. Select Console Application, and name it whatever you want. I named mine "Basic Do Loop".
Spoiler (Click to View)

Step Two

You should have a screen now that shows this code:
Spoiler (Click to View)

Don't worry about all of that. We are only going to work in Sub Main for the time being.

Step Three

This is the Do Loop code itself:
Spoiler (Click to View)

Code
Dim i As Integer
Code
Do While i < 10
    Console.WriteLine(i)
    Console.ReadLine()
    i = i + 1
  Loop

Code
Dim i As Integer
- This declared our variable, i as an integer (number). Note that in the picture this is not under Sub Main, but above it.

Code
Do While i < 10
- This means that the loop will continue looping as long as i is less than 10.

Code
Console.WriteLine(i)
- This writes the value of i in the console window.

Code
Console.ReadLine()
- This can best be explained as a pause in the WriteLine. Without the ReadLine the console window would spam the numbers, and then exit before you could even read anything in the console window.

Code
i = i + 1
- This is saying that i is equal to i + 1. This increments i positively by a value of one.

Code
Loop
- This loops back to the Do While statement above. It will go through the entire thing again, but i is now equal to two and so on. Every time the loop completes one rotation, i will have incremented by a value of one.

Step Four

Voila! You have successfully written, and hopefully understood your Basic Do Loop program.

Step Five

Post a reply with what you thought of this tutorial, how well you understood, etcetra. It only takes ten seconds, and I really would love your feedback.
Are you going to make an all in one thread? (Putting all your tutorials together)
I don't know. Should I? Why would I? I can just link the other tutorials in each tutorial.
Nice Share Mate , I already Knows about it But Thanks for Nice TUT
Hopefully this will help some noobs out.
Was the screnshot of creating a destop application really needed?
(Aug 19, 2012 03:16 PM)The MammoTh Wrote:  Was the screnshot of creating a destop application really needed?

No but why does it matte... oh wait it doesn't.
why isn't "until" explained in with the do loops as well.

also

I =+ 1, i think I = I + 1 should have died with vb6,

however great tutorial, hope it stops some people from asking questions.

Edit:
it'd be nice to see show helpful references
http://msdn.microsoft.com/en-us/library/eked04a7
Lol dude you explain the do loop, except not the do until, do while, loop until, loop while, or just a general while loop? Just make a tut called Loops and explain all the iteration and selection loops in vb.net, would help members much more. Don't put out useless tuts wasting bandwidth, just my feedback 😉
(Aug 19, 2012 03:36 PM)Modesty Wrote:  Lol dude you explain the do loop, except not the do until, do while, loop until, loop while, or just a general while loop? Just make a tut called Loops and explain all the iteration and selection loops in vb.net, would help members much more. Don't put out useless tuts wasting bandwidth, just my feedback 😉

^ Agreed.

This user had 2 threads about his theme. He puts them on a survey link and expect us to download. Ubers like him are retarded.
I just read through my old tutorial and it still seems relevant for all you new VB.Net coders. I realize it isn't the best tutorial in the sense of teaching, but as for referencing and learning, it can be of some benefit.
(May 19, 2014 07:45 AM)eXero Wrote:  I just read through my old tutorial and it still seems relevant for all you new VB.Net coders. I realize it isn't the best tutorial in the sense of teaching, but as for referencing and learning, it can be of some benefit.

I usually attack grave diggers, But this is still relevant and HQ.
[Image: vjPWhyy.gif]
(May 19, 2014 09:17 AM)$lick Wrote:  I usually attack grave diggers, But this is still relevant and HQ.

I wouldn't have grave dug it if it weren't relevant. Some people NEED to read this.
(May 19, 2014 09:53 AM)eXero Wrote:  I wouldn't have grave dug it if it weren't relevant. Some people NEED to read this.

You think so? If it were a good tutorial, maybe. But this is useless, as is gravedigging this thing.
Bit over the top explaining for such a simple concept IMO. Can just as easily be described as:

[Image: 8SQ8H.png]

Execute code (orange) while expression (yellow) is true. Alternatively if you're looking for more in-depth info you could just read: http://msdn.microsoft.com/en-us/library/eked04a7.aspx
Probably coding some useless shit.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by ohxerxeFeb 4, 2018 03:26 PM 3 304 Feb 4, 2018 03:26 PM
Last Post: matt
[Java] by prodigyhfSep 1, 2017 05:22 PM 0 221 Sep 1, 2017 05:22 PM
Last Post: prodigyhf
[C] by hackaquackAug 1, 2014 03:43 PM 15 344 Aug 1, 2014 03:43 PM
Last Post: Masm4ever