How to run a for loop in Minecraft using command blocks

Solution 1:

Edit (2019): McIDE is deprecated. Use datapacks and function files instead. You can use scripting languages to generate the .mcfunction files, e. g. Python, NodeJS or PHP.

Original answer (2017):

You can use a generator such as McIDE. It allows you to create lots of command blocks and use loops and funtions of PHP. It takes some setup tho. You need a spigot server and put the plugin in there. As a text Editor i would recommend Atom.

Website: https://simonmeusel.github.io/mcide/

Docs: https://simonmeusel.github.io/mcide/docs/mcide-plugin/installation.html https://simonmeusel.github.io/mcide/docs/mcide-for-atom/installation.html

To create your config use this: https://simonmeusel.github.io/mcide/generator.html

To create your loop you would need a script like this.

<?php
  for ($i = 100; $i > 0; $i--) {
    echo "/fill " . (-i) . " " . i . " " . (-i) . " " . i . " " . i . " " . i . " air";
  }
?>