Why does kotlin not support the following loop?


#1

Currently I have the following code

var offset = 0 while (offset < data.size) { System.arraycopy(data, offset, bytes, 0, bytes.size); writer.println(bytesToHex(offset, 4, offsetCharCache) + bytesToHex(bytes, 1, bytesCharCache)) offset += 16 }

Why doesn’t kotlin support for loops similar to java so I could type the following

for (var offset = 0; offset < data.size; offset+=16) { System.arraycopy(data, offset, bytes, 0, bytes.size); writer.println(bytesToHex(offset, 4, offsetCharCache) + bytesToHex(bytes, 1, bytesCharCache)) }


#2

I found a solution but I can not delete the thread.

Here is my solution

for (offset in data.indices step 16) {
	System.arraycopy(data, offset, bytes, 0, bytes.size);
	writer.println(bytesToHex(offset, 4, offsetCharCache)     
			+ bytesToHex(bytes, 1, bytesCharCache))
}

#3