开发者

Doubt on scope in loops

just have a question to ask regarding loops.

r=1000000.0;
for (i=0;i<laser_count;i++)
{
 if(this->laser_ranges[i][开发者_如何转开发0] !=-1)
  {
   r= this->laser_ranges[i][0];
  }
 else
 {
   this->laser_ranges[i][0]=r;
 }
}

My question here is if laser_ranges[i][0] = -1 then it is always equal to 1000000.0. Am i right to say this? or will r change accordingly to the loop iteration?


r will change accordingly if the condition this->laser_ranges[i][0] != -1 satisfies. r value otherwise depends on value at the index [i][0].


If typeof r and laser_ranges[][] are same then --> yes, you are correct to say this only first time (Edit: which is a very special case). Usually r might change based on the values of laser_ranges[i][0].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜