Skip to content

for (T x in list)

Control flow

Range-for. in names the collection each value comes from. : is the same form.

for (T x in list) {
}
for (T x : list) {
}
NameTypeDescription
TtypeElement type.
xidentLoop variable.
listiterableArray or iterator-producing call.

Prefer in — it reads as “each x from list”. The C++-style : still works. Parentheses and braces are required.

This is not a protected call and not a C-style for header. Prefer in. The C++-style : in for (T x : xs) is the same loop.

for (Player player in players.GetPlayers()) {
post("Player connected: " .: player.Name);
}

for · array · operator-table