In Dart, the in
keyword is used in the for-in
loop. When we iterate through an iterable, such as a list or a set, the for-in
loop comes in handy.
for (variablename in iterable){
// some code to execute
}
The following code shows how to use the in
keyword in Dart.
void main() {// create listvar lang = ['D','a','r','t'];// iterate through the list// using for-in loopfor (var x in lang) {print(lang);}}
main()
function.main()
, we declare a list called lang
.for-in
loop to iterate through the list lang
and display the items in the list.