Skip to content

Instantly share code, notes, and snippets.

@aruld
Created October 19, 2011 18:30
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save aruld/1299218 to your computer and use it in GitHub Desktop.
Save aruld/1299218 to your computer and use it in GitHub Desktop.
Dart forEach() on a List/Set
main() {
List<String> list = new List<String>();
list.add('one');
list.add('two');
list.add('twelve');
list.forEach((element) => print(element));
Set<String> set = Set.from(list);
set.forEach((element) => print(element));
}
@thesensei254
Copy link

@zwells0225 Two more questions come up, how old is github and how old am I? lol

Copy link

ghost commented Aug 11, 2019

cool !

@Zeeshan0201
Copy link

Zeeshan0201 commented Aug 28, 2019

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

@zwells0225 alright 😄

@Zeeshan0201
Copy link

@zwells0225 Two more questions come up, how old is github and how old am I? lol
@Ngondo haha

@xkdcc
Copy link

xkdcc commented Dec 11, 2019

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

True 😄

@gakyoo
Copy link

gakyoo commented Jan 22, 2020

Definitely because of Flutter.

@Kantulaev
Copy link

Yea flutter

@Javitonito-Javier
Copy link

thx for sharing

@ars27196
Copy link

ars27196 commented Mar 2, 2020

Thanks, I don't even know dart was this old.

@baobuiquang
Copy link

I came here because of Flutter...

Created 9 years ago

@anhpv315
Copy link

thanks

@idrisov-ri
Copy link

yeap, Flutter 😄

@giuliano-macedo
Copy link

thnks my dude, yup, flutter as well

@ench0
Copy link

ench0 commented May 11, 2020

What is Dart? :-)

@oonxselhakeem
Copy link

flutter is here

@adityachaudhari
Copy link

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

haha True !!

@lmas3009
Copy link

lmas3009 commented Aug 2, 2020

Thanks

@AdityaBelani
Copy link

Still Commenting!

@vaibhav-yb
Copy link

Hey, what if we want to execute a block of comments using forEach? Would the following be valid?

list.forEach( (item) {
//do something
//do something else
});

@Babwenbiber
Copy link

Babwenbiber commented Nov 12, 2020

@fourpointfour
list.forEach((item) => print(item)); is nothing else then list.forEach((item) { return print(item);});
since the return type is void, you are not using the return type anyways. So your syntax is totally valid.

@leenabhandari
Copy link

cool

@alperenarc
Copy link

alperenarc commented Dec 7, 2020

You can use set.forEach(print) instead of set.forEach((element) => print(element))

@yeicobF
Copy link

yeicobF commented May 13, 2021

Great!

@luigi-cuomo-3r
Copy link

Awesome!

@jfcompliasset
Copy link

We still use it in 2021, thanks man!

@icgoogo
Copy link

icgoogo commented Oct 7, 2021

i think we should avoid using set for variable name

@gulsenkeskin
Copy link

BIG thanks

@Shuusan
Copy link

Shuusan commented Feb 21, 2022

ありがとうございます!!!!!!!

@amirul12
Copy link

COOL

@GenaroGonzalezz
Copy link

Nice, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment