The Enhansed for Loop (for arrays)

June 17, 2008 at 12:38 pm Leave a comment

It is a specialized for loop that simplifies looping through array in an collection.Itz new 2 java5

Syntax –> for(declaration : expression)

Instead of having three components enhanced has two….the two pieces of for statement are

1. declaration 2.expression

eg:

int [] a={1,2,3,4};

for (int x=0;x<a.length;x++ ) // basic for loop

System.out.print(a[x]);

for(int n : a) // enhanced for loop

System.out.print(n);

output is :—-> 12341234

Advertisements

Entry filed under: Programming.

God’s own country flodded by fake ‘godmen n godwomen’ Pin Prick Attacks —– Avoid all these junk mails , itz fake

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


SUBSCRIBE TO MY FEED

Blog Stats

  • 35,308 hits

Live Traffic Feed

Listed At

Calendar

June 2008
S M T W T F S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

%d bloggers like this: