Never seen before C++ for loop

后端 未结 12 2072
独厮守ぢ
独厮守ぢ 2020-12-07 10:58

I was converting a C++ algorithm to C#. I came across this for loop:

for (u = b.size(), v = b.back(); u--; v = p[v]) 
b[u] = v;

It gives no

12条回答
  •  醉梦人生
    2020-12-07 11:27

    for (u = b.size(), v = b.back(); u--; v = p[v]) 
       b[u] = v;
    

    In above code, u and v are initialized with b.size() and b.back().

    Every time the condition is checked, it executes decrement statement too i.e. u--.

    The for loop will exit when u will become 0.

提交回复
热议问题