Foreach Loop in Different Languages
PHP
<?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
C#
// You can maintain a count of the elements in the collection. int count = 0; foreach (int element in fibarray) { count += 1; System.Console.WriteLine("Element #{0}: {1}", count, element); }
JavaScript
var sum = 0; var obj = {prop1: 5, prop2: 13, prop3: 8}; for each (var item in obj) { sum += item; } console.log(sum); // logs "26", which is 5+13+8
jQuery
var obj = { "flammable": "inflammable", "duh": "no duh" }; $.each( obj, function( key, value ) { alert( key + ": " + value ); });
C++
std::string strarr[] = {"ram", "mohan", "sita"}; for(int i = 0; i < 3; ++i) { listbox.items.add(strarr[i]); }
Oracle
int sum(int[] a) { int result = 0; for (int i : a) result += i; return result; }
These all are the syntax used by different languages if you know some of them please do share it here we will add it above and we will be thankful to you for your contribution. If you love this sharing the do care sharing with others or let us help it more grow by typing a helpful comment according to any loop specialty or anything you do care sharing.
0 Comments
Please add nice comments or answer ....