Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

How to use the in keyword in Dart

Maria Elijah

Overview

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.

Syntax

for (variablename in iterable){  
   // some code to execute  
}

Code

The following code shows how to use the in keyword in Dart.

void main() { 
  // create list
   var lang = ['D','a','r','t']; 
   // iterate through the list
   // using for-in loop
   for (var x in lang) { 
      print(lang); 
   } 
}
Using in keyword

Explanation

  • Lines 1–9: We create the main() function.
  • Line 3: In main(), we declare a list called lang.
  • Lines 6–8: We use the for-in loop to iterate through the list lang and display the items in the list.

RELATED TAGS

dart
communitycreator
RELATED COURSES

View all Courses

Keep Exploring