如何使用if语句循环最佳实践?

时间:2018-01-30 17:07:55

标签: design-patterns

我有代码:

if(conditional)
{
   var r1 = dosomething();
   //do more here

   if(r1 > something)
   {
      var r2 = dosomething();
      //do something
      if(r2 > something)
      {
         ....
         //n if
      }
   }
}

我需要帮助这个代码更好。你能告诉我一些建议吗? 谢谢大家!

1 个答案:

答案 0 :(得分:0)

i = 0;
while (rN > somethingArray[i]){ //if your 'something' is changing in every if use array otherwise simple variable like (rN > something) will work
   rN = dosomething();
   i++;
}