Hi All,
Trying to put together some nested For loops to output the following:
2,2,2
2,2,4
2,2,6
2,2,8
2,2,10
2,4,2
2,4,4
2,4,6
2,4,8
2,4,10
2,6,2
2,6,4
2,6,6
2,6,8
2,6,10
2,8,2
2,8,4
2,8,6
2,8,8
2,8,10
2,10,2
2,10,4
2,10,6
2,10,8
2,10,10
4,10,2
4,10,4
4,10,6
4,10,8
4,10,10
6,10,2
6,10,4
6,10,6
6,10,8
6,10,10
8,10,2
8,10,4
8,10,6
8,10,8
8,10,10
10,10,2
10,10,4
10,10,6
10,10,8
10,10,10
This is what I have so far and it starts off well but then goes off course:
int num = 2;
int x = 3;
const int d = 99;
int k = num;
int j = num;
int i = num;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); //Initialize the serial connection
forLoopTest(num, x);
}
void loop() {
// put your main code here, to run repeatedly:
}
void forLoopTest(int num, int x) {
for (k; k <= 10; k += 2 ) {
Serial.print("1st Number: ");
Serial.println(k);
for (j; j <= 10; j += 2) {
Serial.print("2nd Number: ");
Serial.println(j);
for (i; i <= 10; i += 2) {
Serial.print("3rd Number: ");
Serial.println(i);
}
}
}
}
Here is the current output:
1st Number: 2
2nd Number: 2
3rd Number: 2
3rd Number: 4
3rd Number: 6
3rd Number: 8
3rd Number: 10
2nd Number: 4
2nd Number: 6
2nd Number: 8
2nd Number: 10
1st Number: 4
1st Number: 6
1st Number: 8
1st Number: 10
Any assistance would be greatly appreciated!