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


Fatal error: Uncaught Error: Call to undefined function fetch_rss() in /var/www/ninjatool.dk/blog/wp-content/plugins/wp-cron/wp-cron-dashboard.php:18 Stack trace: #0 /var/www/ninjatool.dk/blog/wp-includes/class-wp-hook.php(298): wp_cron_dashboard('') #1 /var/www/ninjatool.dk/blog/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters('', Array) #2 /var/www/ninjatool.dk/blog/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /var/www/ninjatool.dk/blog/wp-content/plugins/wp-cron/wp-cron.php(62): do_action('wp_cron_hourly') #4 /var/www/ninjatool.dk/blog/wp-includes/class-wp-hook.php(298): wp_cron_hourly_exec('') #5 /var/www/ninjatool.dk/blog/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #6 /var/www/ninjatool.dk/blog/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #7 /var/www/ninjatool.dk/blog/wp-includes/load.php(677): do_action('shutdown') #8 [internal function]: shutdown_action_hook() #9 {main} thrown in /var/www/ninjatool.dk/blog/wp-content/plugins/wp-cron/wp-cron-dashboard.php on line 18