Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
for (size_t i = 0; i < n; i++) {
printf("Item %d = %s\n", i, toString(items[i]));
}
(* output_elem is a printer for elements of [items] *)
items |> List.iteri (fun i x ->
printf "%d: %a" i output_elem x
)
(doseq [[i x] (map-indexed vector items)]
(println i ":" x))
foreach (var (i, x) in items.AsIndexed())
{
System.Console.WriteLine($"{i}: {x}");
}
public static class Extensions
{
public static IEnumerable<(int, T)> AsIndexed<T>(
this IEnumerable<T> source)
{
var index = 0;
foreach (var item in source)
{
yield return (index++, item);
}
}
}
for (var i = 0; i < items.length; i++) {
print('index=$i, value=${items[i]}');
}
items.asMap().forEach((i, x) {
print('index=$i, value=$x');
});
items
|> Enum.with_index
|> Enum.each(fn({x, i}) ->
IO.puts("#{i} => #{x}")
end)
WithIndex =
lists:zip(lists:seq(1, length(Items)), Items),
io:format("~p~n", [WithIndex]).
do i=1, size(items)
print *,i, items(i)
end do
items.eachWithIndex {
x, i -> println "Item $i = $x"
}
mapM_ print (zip [0..] items)
for (var i in items) {
console.log("index=" + i + ", value=" + items[i]);
}
items.forEach((val, idx) => {
console.log("index=" + idx + ", value=" + val);
});
items.forEachIndexed { i, x ->
println("i=$i x=$x")
}
(loop for i from 0 and x across items
do (format t "~a = ~a~%" i x))
for i, x in ipairs(items) do
print('Index: '..i..', Value: '..x)
end
foreach ($items as $i=>$x)
{
echo "i=$i, x=$x"; echo '<br>';
}
var I:Integer;
Items: array of String;
[..]
for I := 0 to high(Items) do
WriteLn('Item ', I, ' = ', Items[I]);
for i, x in enumerate(items):
print(i, x)
for x in enumerate(items): print(x)
items.each_with_index do |x, i|
puts "Item #{i} = #{x}"
end
items.each_index{|i| puts "Item %d = %s" % [i, items[i]]}
for (i, x) in items.iter().enumerate() {
println!("Item {} = {}", i, x);
}
items.iter().enumerate().for_each(|(i, x)| {
println!("Item {} = {}", i, x);
})
val items = List("a", "b", "c")
items.zipWithIndex.foreach{ case (item, index) =>
println(s"$index => $item")
}
(define (display-list items)
(define (display-list items i)
(if (not (null? items))
(begin
(display (string-append
(number->string i)
": "
(number->string (first items))
"\n"))
(display-list (rest items) (+ i 1)))
'done))
(display-list items 0))
items withIndexDo: [:item :index |
Transcript showln: 'item: ' , item asString , ' index: ' , index asString].
For i = LBound(items) To UBound(items)
x = items(i)
Debug.Print i & ": " & x
Next