Sometimes you may wish to call other tasks from a main task.
Asume we have build and a dist tasks. By passing the option --build to the dist task, the build task should run before.
Unfortunately, the build task repeats in an endless loop ?
grunt dist --build
Example (short and simplified):
  // command: grunt build
  grunt.registerTask('build', 'Dist task', function() {
    grunt.initConfig({...}); // cssmin, htmlmin tasks etc...
    grunt.task.run(tasksArray); 
  });
  // command: grunt dist
  grunt.registerTask('dist', 'Build task', function() {
    // Option: --build
    var buildOption = grunt.option('build');
    if (buildOption != null) {
      grunt.task.run('build'); // Run the build task first
    }
    grunt.initConfig({...}); // compress task etc...
    grunt.task.run(tasksArray);
  });
How can I prevent the endless repeat of the build task?
Note:
Of course I may use something like: grunt build && grunt dist, but the example above is (as mentioned) a simplified example for something bigger.