list foreach
时间: 2023-10-27 14:43:16 浏览: 87
The foreach loop is a control flow statement used in various programming languages to iterate over a collection or array of items and perform a specific action on each item in the collection. Here are some examples of foreach loops in different programming languages:
1. C#:
foreach (var item in collection)
{
// Perform action on each item in the collection
}
2. Java:
for (int item : collection)
{
// Perform action on each item in the collection
}
3. Python:
for item in collection:
# Perform action on each item in the collection
4. JavaScript:
collection.forEach(function(item) {
// Perform action on each item in the collection
});
5. PHP:
foreach ($collection as $item) {
// Perform action on each item in the collection
}
6. Ruby:
collection.each do |item|
# Perform action on each item in the collection
end
阅读全文