I_n_test = I_N在for循环内意味着什么?

问题描述 投票:0回答:3

我试图在这里理解代码:http://devernay.free.fr/vision/src/prosac.c

主要是因为我想将其翻译成python。

以下是代码段:

for(n_test = N, I_n_test = I_N; n_test > m; n_test--) { 
  // Loop invariants:
  // - I_n_test is the number of inliers for the n_test first correspondences
  // - n_best is the value between n_test+1 and N that maximizes the ratio                       
  I_n_best/n_best
  assert(n_test >= I_n_test);
  ...
  ...
  // prepare for next loop iteration
  I_n_test -= isInlier[n_test-1];
} // for(n_test ...

那么循环语句中的I_n_test = I_N;是什么?

这是停止状态吗?那不应该是"=="吗?

c loops for-loop syntax
3个回答
2
投票

您可以阅读

 for(n_test = N, I_n_test = I_N; n_test > m; n_test--)

as

 for (initialization ; loop-checking condition; increment/decrement)

根据规格,§6.8.5.3C11章>

The statement

  for ( clause-1 ; expression-2 ; expression-3 ) statement
    

表现如下:表达式expression-2是控制表达式,它是 在每次执行循环主体之前进行评估。表达式expression-3为 每次执行循环主体后,将其评估为void表达式。如果clause-1是一个 声明,它声明的任何标识符的范围是声明的其余部分,并且 整个循环,包括其他两个表达式;按执行顺序达到 在对控制表达式进行第一次评估之前。如果clause-1是表达式,则为 在对控制表达式进行第一次评估之前将其评估为空表达式。

因此,按照语法,n_test = N, I_n_test = I_N是包含初始化语句的表达式。它们之间用comma operator分隔。


0
投票

I_n_test = I_N;)是否处于停止状态?


0
投票

for(n_test = N,I_n_test = I_N; n_test> m; n_test-)

© www.soinside.com 2019 - 2024. All rights reserved.