如何重复这种类型的for循环?

时间:2016-01-12 04:38:06

标签: loops

for (int i=0; i<oMsg.length(); i = i + interval) {
    work += oMsg.substring(i, i+1); 
}

我想重复这一点但只改变int i = part 例如

for (int i=0; i<oMsg.length(); i = i + interval) {
    work += oMsg.substring(i, i+1); 
}
for (int i=1; i<oMsg.length(); i = i + interval) {
    work += oMsg.substring(i, i+1); 
}

for (int i=2; i<oMsg.length(); i = i + interval) {
    work += oMsg.substring(i, i+1); 
}

1 个答案:

答案 0 :(得分:0)

添加第二个循环:

for (int j = 0; j < 3; ++j) {
  for (int i = j; i < oMsg.length(); i += interval) {
    work += oMsg.substring(i, i + 1); 
  }
}