I can not figure out what is wrong with this cycle.

byte[] b = writeLen(command); long retLen = b.length + command.length() + 1; byte[] ret = new byte[retLen]; print(b.length); for (i = 0; i < b.length; i++) { print(i); ret[i] = b[i]; } print("^"); 

When executed, the script cannot exit the for loop. The output of the command is as follows:

6 * 1 0 0 0 0 0 and to infinity zeros.

The six and the asterisk are derived from the WriteLen procedure before leaving it. Unit - length b. And a miracle happens in the cycle - the counter remains unchanged.

  • There was a long one, changed to int, but nothing has changed. - ichbinkubik

3 answers 3

use System.arraycopy () to copy an array.

  • With system.arraycopy this site works. But the real problem was solved when I declared int i not inside the try block, but in the general procedure block. - ichbinkubik

It seems that in reality there is so for (i = 0; i <b.length; i ++) {print (i); i = b [i]; }

    Judging by the code, you do not specify the type of the variable i, it is better to write another heading:

     for(int i=0; i<b.length; i++) 
    • In theory, this does not interfere with implementation. Here, for example, I run <br/> for (i = 0; i <10; i ++) {print (i); } And it works great in both bsh and bsh2 - cy6erGn0m
    • The idea does not interfere. But you see that the code is quite reasonable, so I think this is one of the options. - Sergey