在我的颤振应用程序中,我有一个使用对象框飞镖保存在本地移动存储中的实体。我想查询数据库以获取特定读数,如果该读数不可用,我需要继续查询,除非找到一个读数。伪代码如下所述。我想知道效率方面哪个更好。
选项1
while {
var readings = hitDatabaseFor1Reading()
if(reading.isNotEmpty()) {
// stopWhileLoop
// perform operation
} else {
// change query condition
}
}
选项 2
var readings = hitDatabaseForAllReadings()
sortReadingsAsPerDate()
if(readings.isNotEmpty) {
//perform operation on first reading
}