Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the diffrence between for and foreach?

Answer Posted / nishant lokhande

foreach loop is also called as advance for loop
foreach loop is used to display an elements in collection.
eg.

To print arry element
by using foreach loop


public class Demo
{
public static void main(String args[])
{
String[] data = { "tomato", "potato","onion" };
for (String s : data)
{
System.out.println(s);
}
}
}


By using for loop

public class Demo
{

public static void main(String args[])
{
String[] data = { "tomato", "potato","onion" };
for(Iterator it = data.iterator();it.hasnext();)
{
String data1 = (String)it.next();
System.out.println(data1.charAt(0));
}

}

}

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we upload a file in php?

961


What is meant by PEAR in PHP?

923


Why do we use php?

909


What is good average session duration?

959


Explain what is the function file_get_contents() usefull for?

895


Explain what does the function get_magic_quotes_gpc() means?

882


How to get the ip address of the client?

9124


What is the difference between overloading and overriding in php?

986


What is the purpose of using php?

996


When sessions ends?

905


What is a string in r?

881


What is the difference between unset and unlink?

920


Who is the father of php and what is the current version of php and mysql?

1211


What is php and how do you use it?

937


How can we check the value of a given variable is alphanumeric?

936