Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: changing for loop to while statement..

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default changing for loop to while statement..

    Hello again,
    I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff). Any suggestions would be appreciated. thanks

    public void run() {
    		    int i = 10;	
    			while (i>=1) {
    		    println(+i+"...");
    			i--;
    			}
    			println("liftoff...");
     
     
     
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: changing for loop to while statement..

    Are there any compiler errors?
    Where and what is the definition for the println() method?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    15
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: changing for loop to while statement..

    sorry about the confusion...for some reason the code is working fine???? I copied it and pasted it to a new project and it works, feel free to delete this tread and thanks for the reply though!

  4. #4
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: changing for loop to while statement..

    Quote Originally Posted by Norm View Post
    Where and what is the definition for the println() method?
    Because he is using third party Java libraries, the definition of println is stored in the ACM libraries
    within

    import acm.program.*;
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. help with defining a changing variable within a loop
    By uswhovian in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 9th, 2013, 11:30 AM
  2. help with defining a changing variable within a loop
    By uswhovian in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 9th, 2013, 10:30 AM
  3. help with defining a changing variable within a loop
    By uswhovian in forum Loops & Control Statements
    Replies: 3
    Last Post: March 9th, 2013, 10:30 AM
  4. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  5. Changing strings in a switch statement n stroing it in an array
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 25
    Last Post: February 20th, 2013, 05:25 PM