我在数据库中有一些值。
我正在拿它并根据
进行比较
我的需要,但问题是它将它与列表的最后一个值进行比较
如果我得到我的值与条件相比,循环应该断开并使用循环中的中断如果条件但它不起作用。
像数据一样。
serial_number=1
range_one_start=1.00 to range_one_end=1.10
range_two_start=20.00 to range_two_end=20.40
rate=1.00
------
serial_number=2
range_one_start=1.11 to range_one_end=1.20
range_two_start=20.00 to range_two_end=20.50
rate=2.00
------
serial_number=3
range_one_start=1.21 to range_one_end=1.30
range_two_start=20.00 to range_two_end=20.50
rate=3.00
依此类推我想得到serial_number 2的数据,所以我将传递数据
Range_one = 1.12和Range_two = 20所以在ans中我将得到率2.00
所以if条件就像
if(1.12 >= 1.11 && 1.12 <= 1.20 && 20 >= 20.00 && 20 <= 20.50 )
{
Double rate_value = 2.00;
break;
}
下面的是我的循环
for (int i = 0; i < list.size(); i++) {
Double serial_number = Double.parseDouble(list.get(i).Serial_number_);
Double range_one_start = Double.parseDouble(list.get(i).Range_one_start);
Double range_one_end = Double.parseDouble(list.get(i).Range_one)end);
Double range_two_start = Double.parseDouble(list.get(i).Range_two_start);
Double range_two__end = Double.parseDouble(list.get(i).Range_two_end);
Double rate = Double.parseDouble(list.get(i).Rate);
if(Range_one >= range_one_start && Range_one <= range_one_end && Range_two >= range_two_start && Range_two <= range_two__end )
{
Double rate_value = rate;
break; // this break statement is not working its not breaking the loop.
}
}
提前致谢
答案 0 :(得分:0)
使用以下代码:
for (int i = 0; i < list_p_to_p_clr_buffalo.size(); i++) {
Double serial_number = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).Serial_number_P_To_P_CLR_Buffalo);
Double range_one_start = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).fat_from_P_To_P_CLR_Buffalo);
Double range_one_end = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).fat_to_P_To_P_CLR_Buffalo);
Double range_two_start = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).CLR_from_P_To_P_CLR_Buffalo);
Double range_two__end = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).CLR_to_P_To_P_CLR_Buffalo);
Double rate = Double.parseDouble(list_p_to_p_clr_buffalo.get(i).rate_P_To_P_CLR_Buffalo);
Log.e("IF Condition == >", " " +(fatRate >= range_one_start && fatRate <= range_one_end && clrRate >= range_two_start && clrRate <= range_two__end ));
try {
if(fatRate >= range_one_start && fatRate <= range_one_end && clrRate >= range_two_start && clrRate <= range_two__end ) {
Log.e("IF CONDITION DEBUG == >", "CONDITION OK");
pToPClrRate = rate;
Log.e("Rate***pToPClrRate* Buff** ==>",""+pToPClrRate);
runOnUiThread(new Runnable() {
public void run() {
// some code #3 (Write your code here to run in UI thread)
condition = true;
refreshBtn.setEnabled(true);
}
});
break; // this break statement is not working its not breaking the loop.
}
else{
runOnUiThread(new Runnable() {
public void run() {
// some code #3 (Write your code here to run in UI thread)
condition = false;
refreshBtn.setEnabled(false);
}
});
Log.e("IF CONDITION DEBUG == >", "CONDITION no else part");
}
} catch (Exception e) {
// TODO: handle exception
Log.e("Exception == >", " "+ e);
}
}
结论:无论如何都要检查你的情况。