Use a recursive method, travel, to journey from start to finish

using System;
public class Journey {
private static String indent = "";
public static void TakeOneStep(int step) {
Console.WriteLine("{0}Taking step {1}", indent, step);
}
public static void Move(int start, int finish) {
string oldIndent = indent;
Console.WriteLine("{0}Starting move from {1} to {2}", indent, start, finish);
if (start < finish) {
TakeOneStep(start);
indent += " ";
Move(start+1, finish);
indent = oldIndent;
}
Console.WriteLine("{0}Finishing move from {1} to {2}",indent, start, finish);
}
public static void Main(String [] args) {
Move(1, 10);
}
}
Related examples in the same category