Just found out how great array with for loop is. it has saved many bytes of memory, and now I am rewriting everything with for loop code. Here I encounter a problem. I need to write a for loop, but I can't figure out a function to do so
for i= 5,4,3,2 // here is the for loop i: 5 to 2
x=(i-2); // this is easy, 5-2=3; 4-2=2.... etc
3,2,1,0
y=??? //but this???
4,7,10,13
/// here are some of my thinking or attempts, but they don't work; so my question: is there any tips for doing thing like this? and can someone solve this problem for me?
If you want a for loop to create the output 4, 7, 10, 13 when i runs from 1 to 4, there seems to be nothing difficult about that:
for(int i=1; i<=4; i++)
{
int j = i - 1 - 5; // j will be -5, -4, -3, -2
int k = i + 4; // k will be 5, 6, 7, 8
Serial.println(2*k + j - 1);
}
Of course, all the types could be byte. I think that the problem you are having is not seeing that you can introduce intermediate values in the loop. While they are not strictly necessary, it certainly makes it easier to decompose the problem.