[igt-dev] [PATCH i-g-t] tests/i915/gen_mmap: fix no-op loops

Jani Nikula jani.nikula at linux.intel.com
Wed May 8 11:27:56 UTC 2019


On Tue, 07 May 2019, "Ser, Simon" <simon.ser at intel.com> wrote:
> On Tue, 2019-05-07 at 15:31 +0100, Chris Wilson wrote:
>> Quoting Simon Ser (2019-05-07 13:44:41)
>> > The loop condition is never satisfied, since after filling the
>> > array i > 0. For
>> > this reason the loop is always a no-op.
>> > 
>> > Use a more conventional loop instead.
>> 
>> Or a classic while loop? Bad me for not reading the check was
>> back-to-front.
>
> You mean while(i--)?
>
> I generally prioritize code clarity in these situations, hence the for
> loop. Also not a fan of decrementing operators returning a value.

FWIW I always go for (i = 0; i < N; i++). It takes half an eyeblink for
that to sink in.

BR,
Jani.


-- 
Jani Nikula, Intel Open Source Graphics Center


More information about the igt-dev mailing list