loops - On every third iteration C# -


this question has answer here:

i have loop performing simple task me every time variable multiple of 3, have create big loop contains every multiple of 3 logical or (3, 6, 9, ...). wondering if there more efficient way of doing this.

this code snippet:

if (wavecounter == 3 || wavecounter == 6 || wavecounter == 9 || wavecounter == 12) {     amount = 0.03f;     daynight.lightamout = amount;     daynight.light.intensity = mathf.lerp(daynight.light.intensity, daynight.lightamout, fadetime * time.deltatime); } else {    amount = 1f;    daynight.lightamout = amount;    daynight.light.intensity = mathf.lerp(daynight.light.intensity, daynight.lightamout, fadetime * time.deltatime); } 

my objective here rid of writing multiples of 3 in if statement , still achieving same goal every time wavecounter variable next multiple of 3.

if((wavecounter % 3) == 0) 

modulo arithmetic: divides number 3 , checks remainder. number divisable 3 has no remainder (and ==0)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -