Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

JAVA loop without variable?

for "for" and "while" loop i need to add variable, even when i don't actually need any in code inside of the loop. Is there any loop without need of use such dummy variable?

Update:

Using intuition i did try for () and while () but they gave me an error ;)

3 Answers

Relevance
  • cpcii
    Lv 7
    6 years ago

    Neither really need a variable for working, ( i can't remember for a for loop exactly) but a while loop can be done as

    while (

    do something until match your condition

    breaK:

    )// end while

  • Anonymous
    6 years ago

    So you want to make an infinite loop? In that case, just use while (true) { do stuff forever }

  • John
    Lv 7
    6 years ago

    for(;;) { }

    do { } while(expression);

    while(true) { }

    this one you wont understand

    collection.stream().forEach(e -> System.out.println(e));

Still have questions? Get your answers by asking now.