1

I am trying to understand this for loop pattern:

 for { // Shift n right by 1 before looping to halve it. n := shr(1, n) } n { // Shift n right by 1 each iteration to halve it. n := shr(1, n) } { ... } 

I guess it can be translated into

for(uint256 n = n/2; n > 0; n = n/2) { ... } OR for(n >> 1; n > 0; n >> 1) { ... } 

Is that correct ? I'm mainly concerned with the stop (middle) parameter but maybe even other parameters are incorrect.

1 Answer 1

0

This is solved. I'm pretty sure this is correct now as I can now get the desired result I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.