Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6524774

Nested for loops in Java

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6
    • specification
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      It would be very convenient to be able to have multiple nested foreach loops into one foreach loop by adding as many ":" as required.

      JUSTIFICATION :
      It's necessary to avoid wasting code space and the code will be very much like reading a sentence.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      this would require enhancing the current foreach loop in the following manner:

      for(City city : Array<Country> countries : Array<Continent> continents : Array<planet> planets) {
          System.out.println("Here's a list of all the cities in the solar system: " + city.getName());
      }

      CUSTOMER SUBMITTED WORKAROUND :
      use multiple for each loops; for example:

      for(Planet planet : planets) {
         for(Continent continent : planet) {
            for(Country country : continent) {
              for(City city : country) {

          System.out.println("Here's a list of all the cities in the solar system: " + city.getName());

      }

            abuckley Alex Buckley
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: