Warning: Declaration of GTranslate::widget($args) should be compatible with WP_Widget::widget($args, $instance) in /var/www/ninjatool.dk/blog/wp-content/plugins/gtranslate/gtranslate.php on line 0
Alternating directions | NinjaTool inc.

Alternating directions

Posted by on February 23, 2011

Just a quick thought :)
If you want to alternate between -1 and 1 in a for-loop, say for the purpose of changing direction or something similar, and you don’t want to add an extra variable to manually alternate in each run-through, this works just fine:

for (int i=0; i < something; i++){
   dir = ((i % 2) * 2) - 1;
   // dir is now good for multiplying onto vectors or whatever.

103 Responses to Alternating directions

Leave a Reply