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

What is advanced php programming?

1029


What is the use of pear in php?

1011


How can we make a constant in php?

995


What is orm in php framework?

1037


Is php front end?

949


What are the features of php 7?

1063


How to get the total number of values in an array?

1011


What is the difference between rest and soap?

1145


What is session_start () in php?

996


What is the super method?

1017


What are the rules to determine the “truth” of any value which is not already of the boolean type?

957


What is difference between compile time and run time polymorphism?

1013


What are Routines?

2229


Is age an interval or ratio?

973


What is PHP's configuration file called?

1186