美文网首页
Flutter 常用循环函数 forEach map where

Flutter 常用循环函数 forEach map where

作者: 小乔与周瑜 | 来源:发表于2021-05-21 08:56 被阅读0次

for循环

```java

List myList=[1,2,3,4];

List newList = newList();

for (var I= 0 ;I < myList.length  ; i++) {  newList.add(myList[I] * 2) ; }

```

for..in..

```python 

List myList=[1,2,3,4];

List newList = newList();

for(var I in myList){ newList.add( myList[I] * 2 );}

```

forEach

```python

ListmyList = [1,2,3,4];myList.forEach((v){

print(v);

});

```

map

```python

var newList = myList.map((v){

return v  *2;

});

print(newList.toList());

```

where

返回满足条件的值

```python 

List myList2 = [1,2,3,4,5,6,7];

var newList2 = myList.where((v){

return v > 5;

});

print(newList2.toList());  // 6,7

```

any

只要有一个满足条件就返回true

```python

var  f = myList.any((v){

return v > 5;

});

print(f);  // true

```

every

条件都满足了才能返回true 否则返回false

```python

var f2 = myList.every((v){

returnv > 5;

});

print(f2); // fasle

```

相关文章

网友评论

      本文标题:Flutter 常用循环函数 forEach map where

      本文链接:https://www.haomeiwen.com/subject/pzgijltx.html