Results 1 to 2 of 2
  1. #1
    kedecr is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default While loop problem

    how do I make this for loop into a while loop?

    Scanner sc = new Scanner(;
    System.out.print("Enter start number: ");
    int start = sc.nextInt();
    System.out.print("Enter last number: ");
    int end = sc.nextInt();
    int count = 0;
    for (int i = start; i <= end; i+=3) {
    System.out.print(i + " ");
    if (count==10) {
    count = 0;

    // it prints every third number (user input numbers).... and I want to do the same with a while loop but I can't figure it please!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    As you could've known from your text book, a for-loop like this:

    Java Code:
    for (<init>; <cond>; <incr>) <statement>;
    is equalvalent to a while-loop like this:

    Java Code:
    while (<cond>) {
    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Problem with a for loop
    By ile4 in forum New To Java
    Replies: 3
    Last Post: 12-02-2010, 03:23 PM
  2. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM
  3. Some while loop problem need help
    By shaggyoo7 in forum New To Java
    Replies: 4
    Last Post: 01-14-2009, 08:16 PM
  4. Loop Problem
    By jralexander in forum New To Java
    Replies: 4
    Last Post: 12-02-2008, 08:08 AM
  5. For loop problem
    By mcal in forum New To Java
    Replies: 32
    Last Post: 01-25-2008, 04:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts