Visual Basic Tutorial – 30 – Do Until Loop

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






31 responses to “Visual Basic Tutorial – 30 – Do Until Loop”

  1. Matt Black Avatar

    I was wondering if anyone could help me with this bit of code I have made.. I want it to loop for multiple users but I can only come up with a loop for just me.. I want it to loop for ExampleUser1 and ExampleUser2.. Obviously I want it to loop for more users than just two but this is for example purposes.. I have tried….

    Do Until userName.ToLower() = "ExampleUser1" or "ExampleUser2" etc ..

    But this is not a very neat or efficient way of doing it and to add onto those two points It gives me an invalid cast exception.

    I have thought up what if I could make a loop that works with an if statement like..

    If userName.Tolower() = "ExampleUser1" Then


    ElseIf userName.ToLower() = "ExampleUser2" Then



    End if


    Module Module1

    Sub Main()

    Dim userName As String = Nothing
    Dim userPass As String = Nothing

    Console.WriteLine("What is your User Name?")
    userName = Console.ReadLine()

    Console.WriteLine("What is your User Password?")
    userPass = Console.ReadLine()

    '''''''''''''''I need help starting here….'''''''''''''

    Do Until userName.ToLower() = "ExampleName1" And userPass = "ExamplePassword1"
    Console.WriteLine("Your Username or Password have been typed incorrectly! Please retype your information.")

    Console.WriteLine("What is your User Name?")
    userName = Console.ReadLine()


    Console.WriteLine("What is your User Password?")
    userPass = Console.ReadLine()


    If userName.ToLower() = "ExampleName1" And userPass = "ExamplePassword1" Then

    Console.WriteLine("Welcome " & userName)

    End If

    End Sub

    End Module

  2. weshuiz13 Avatar

    somebody know what is rong with this code?
    Dim R As Integer = 0
    Do Until R = (NumericUpDown2.Value)

  3. Jonathan Dalmida Avatar

    how do u repeat the number. I want it to repeat the num as many times as the number it is. like if the number is 3 I want it to write 3, three times.

  4. Jason Malouin Avatar

    is it possible to loop blocks of code ?

  5. ryanvibe11 Avatar

    Shame about wasting those mints, could have eaten them later

  6. PISTOL PETE Avatar

    Lol you must have been making these videos while you were sick.

  7. William Remaley Avatar

    Thank you! I was trying to figure out how to write a loop to count down from 10 to 1, and I couldn't figure out what I was doing wrong. I had all these readlines and stuff in there, I guess that's what was messing me up. You saved my butt!

    Thanks again!

  8. bahamasbred Avatar

    How do I implement Do until and error occurs.

    I want to avoid usin. On error resume next.

  9. Colin Stodd Avatar

    So num1 += can only be a 1 or 2? Everything else seems to go bonkers.

  10. Kodringo Avatar

    It happened to me too xD

  11. lam neihofarn Avatar

    Your icon scared me. Haha i thought i had a spider on my screen xD

  12. Leamsi Ordnavi Avatar

    Thanks one more time! 😀

  13. Kodringo Avatar

    Just to let you know, it was explained already in the early math tutorials

  14. TYMON399 Avatar

    ok, thank allot i understand it now, and appreciate your help. You earned yourself a sub 😀

  15. Rodolfo Silva Avatar has it's own syntax. so no it wont work, but "num1+= 1" will..

  16. Rodolfo Silva Avatar

    So "num1 + 1" will just make the calculation and won't put the result inside the variable but "num1 += 1" will

  17. Rodolfo Silva Avatar

    it get's the value already in the variable and add's one…

    like imagine "num1" has a value already of "3" inside, then he gets that value and add's one and places the result(the number "4") inside the variable again..

    another and simple way(newbi friedly) to get that would be:
    "num1 = num1 + 1"

    "num1 += 1" is just a shot way of getting the above!

    You also have "-=" for subtraction , "/=" for division and "*=" for multiplication…

  18. TYMON399 Avatar

    Why is it num1 += 1 and not + 1?

  19. Robus Subnor Avatar

    as long as num1 istn something like 7 or 4 already

  20. Robus Subnor Avatar

    cuz num1 cant = 10
    every loop you add 3
    —-> num1 = 3 then 6 then 9 then 12 ……
    you could do Do Until num1 >= 10

  21. Gabriel Evans Avatar

    is this all the same for other kinds of programs that use visual basic? I'm not exactly keen on making all kinds of console applications. I'd like to make windows applications as well…
    Just asking. 🙂

  22. Rahil Wazir Avatar

    you do waste almost 1.5 mints to open the software to the new project

  23. poetmm Avatar

    i thought the do until is a postest loop where it evaluate occurs after the instructions within the loop are process so it will read


    instructions goes here

    loop until num1 = 10

    because if that is the case whats the point of using the while loop if they are both use the same way

  24. LoganMeistro Avatar

    haha nice, about the num1 += 1 before the console.writeline, I really should watch the next tutorial before commenting! Great set of tuts, good job!

  25. LoganMeistro Avatar

    @desiderataguitarista Also, num1 = num1 + num1 is not the same as the other two, you meant, num1 = num1 + 1

    Another note to Sam, you could have also kept the do loop at 10, and num1 at 0, and placed your num1 += 1 before your console.writeline(num1) and it would have read 1 – 10. That's fairly important to understand, because it doesn't take precious resources in a bigger application by running another unnecessary loop. However, if you did want it to start at 0, then it is necessary!

    Great tut

  26. Ignacio Lopo Avatar

    @desiderataguitarista I wouldn't count on that, as you'll see in this series of tutorials, many things are different from C++, besides I already figuered it out: the statement X++ doesn't work on Visual Basic. On one of the tuts, Sam accidentally wrote num1++ and then he corrected it to num1 += X and said that he'd confused 2 languages (C++ and Visual Basic)

  27. Ignacio Lopo Avatar

    So in Visual Basic 2010 the statement "num1++" doesn't work?

Leave a Reply

Your email address will not be published. Required fields are marked *