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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -