Results 1 to 1 of 1
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Enhanced for loop

    Java SE platform version 5.0 introduces for loop with a little modification to simplify things for the developers.

    Java Code:
     [COLOR=black][FONT=&quot]String countries[]={[/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Australia"[/FONT][/COLOR][COLOR=black][FONT=&quot],[/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Germany"[/FONT][/COLOR][COLOR=black][FONT=&quot],[/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"France"[/FONT][/COLOR][COLOR=black][FONT=&quot],[/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Itlay"[/FONT][/COLOR][COLOR=black][FONT=&quot]};[/FONT][/COLOR]
      
      [B][COLOR=#7f0055][FONT=&quot]for[/FONT][/COLOR][/B][COLOR=black][FONT=&quot] (String element : countries) {[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]System.[/FONT][/COLOR][I][COLOR=#0000c0][FONT=&quot]out[/FONT][/COLOR][/I][COLOR=black][FONT=&quot].println([/FONT][/COLOR][COLOR=#2a00ff][FONT=&quot]"Element: "[/FONT][/COLOR][COLOR=black][FONT=&quot] + element);[/FONT][/COLOR]
      [COLOR=black][FONT=&quot]}
    [/FONT][/COLOR]

    Last edited by Java Tip; 11-04-2007 at 06:02 PM.

Similar Threads

  1. while loop
    By michcio in forum New To Java
    Replies: 5
    Last Post: 01-27-2008, 12:56 AM
  2. A loop that doesn't loop
    By MichYer in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 08:44 AM
  3. While loop
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 03:11 PM
  4. Enhanced For loop In Java
    By goldhouse in forum Advanced Java
    Replies: 1
    Last Post: 05-06-2007, 04:26 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
  •