# loop方法遍历
loop循环适用于查询数据集`select()、selectForMap()`的结果输出,针对于返回结果List和map进行循环遍历
表达式使用
```java
List<RowData> select = Db.name("tg_task").where("status", 1).select();
Loop.forEach(select, new RowDataCallback<RowData, Integer>() {
@Override
public void onData(RowData data, Integer index) {
data.set("qq","123");
}
});
或
Map<Integer, RowData> integerRowDataMap = Db.name("tg_task").where("status", 1).selectForMap();
Loop.forEach(integerRowDataMap, new RowDataCallback<RowData, Integer>() {
@Override
public void onData(RowData data, Integer index) {
data.set("qq","123");
}
});
```
运行结果
```java
{
"code": 1,
"msg": "success",
"data": [
{
"qq": "123",
"id": "1"
},
{
"qq": "123",
"id": "9"
}
]
}
或
{
"code": 1,
"msg": "success",
"data": {
"1": {
"qq": "123",
"id": "1"
},
"2": {
"qq": "123",
"id": "2"
}
}
}
```