Do....while Loop


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Do....while Loop

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Do....while Loop

    Hi,

    I have wrote a for loop that writes a program that asks the user to type in three numbers and then displays the total of those numbers

    public class Forloop3_3a
    {
    public static void main(String[] args)
    {
    int num1;
    int total = 0;
    for (int i=1; i<=3; i++ ) {
    System.out.print("Enter Numbers: ");
    num1 = EasyIn.getInt();
    total = total + num1;

    }
    System.out.println("Total is " + total);
    }
    }


    How can i do this using a do...while loop? so that you can type in numbers continually until you want to finish

    Thanks in advance

  2. #2
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108
    So you want to be able to enter numbers until the user wants to stop?




    Try something like this:


    do{

    Do the adding


    }while(num1!==0); // If the user types in 0 the loop stops


    Hopefully this helps

  3. #3
    Join Date
    Dec 2004
    Posts
    46
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center