ubyte[256] data;
if (data.length > 0) {
ubyte i = 0;
do {
writeln(i);
} while ((++i) != cast(ubyte)data.length);
}
You also need to add an assert before the if to check that the last index can be represented as an ubyte. So probably not worth it.
