learning loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adnan12
    New Member
    • Mar 2007
    • 3

    learning loop

    I want to write a short program using loop. I wrote one but it doesn’t working. I’m learning loops so it’s hard to find my mistakes. Here’s my code. Please define and correct where I made a mistake.

    Code:
    class Ce {
        public static void main(String[] args) {
    	String tence = "I can use loops.";
    	int count = 0;
    	while (count++ <= 25000) {
    	    System.out.println(tence);
    		break;
    	}
    	    System.out.println("\nI wrote sentence " + count + " times.");
    	    System.out.println("I'm learning my lesson.");
    	}
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Remove that 'break' statement and see what happens then. A break statement
    stops your loop immediately and the flow of exectution continues at the first
    statement after the loop.

    kind regards,

    Jos

    ps. if you don't have the patience, reduce the number 25000 to, say 25 or so.

    Comment

    Working...