Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Learning Loops in VB.NET for Game Developm...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Learning Loops in VB.NET for Game Development
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-06-18

    Table of Contents:
  • Learning Loops in VB.NET for Game Development
  • While...End continued
  • Do...Loop
  • Do...Loop continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Learning Loops in VB.NET for Game Development - Do...Loop


    (Page 3 of 4 )

    The Do ...Loop statement offers another loop that we can use, the Do loop. It's similar to While ...End , but it's more complex, supporting a variety of behaviors. In its most basic form, it's not any different from an infinite While loop, except we're able to omit the expression altogether. Here's a new version of our input-echoing loop, rewritten using Do ...Loop:


    Dim input As   String

    Do

    input = Console.ReadLine()

    Console.WriteLine(input)

    Loop


    If we want to terminate the loop, we have to do so manually by using Exit, as we did earlier with the infinite While loop, since we didn't provide an expression. However, we must specify that we're exiting a Do loop instead of a While loop. Here, we exit if the user types “quit”:


    Dim input As   String

    Do

    input = Console.ReadLine()

    Console.WriteLine(input)

     If input.ToLower() = "quit"   Then

     Exit Do

     End If

    Loop


    The real value in the Do loop, however, lies in its support for multiple behaviors. The loop supports two basic modes of behavior: While and Until . We can either tell our loop to run while a condition is true, or we can tell our loop to do something until a condition is true. Let's take these two behaviors one at a time, starting with the While behavior. Let's create a loop that will echo user input as long as (while) the user does not type “quit”:


    Dim input As   String = ""

    Do While input.ToLower() <> "quit"

    input = Console.ReadLine()

    Console.WriteLine(input)

    Loop


    As before, we must assign a value to input. Actually, as you've probably noticed, the above loop bears a strong resemblance to our earlier While loop. Hold that thought for just a moment while we move on to the second mode of behavior, Until. Let's recreate our loop to echo user input until the user types “quit”:


    Dim input As   String = ""

    Do Until input.ToLower() = "quit"

    input = Console.ReadLine()

    Console.WriteLine(input)

    Loop


    Though the above two loops function the exact same way, the expressions used are opposites. In effect, Do Until operates while the expression comes out False . Then, when it comes out True, the loop terminates. Sometimes, this mode of behavior is more straightforward and readable. In fact, it suits our example quite well.

    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Hello,This is a continuation of my series on learning Visual Basic through the...
     

    VISUAL BASIC.NET ARTICLES

    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT