Array loops. how to simplify this?

Hi, i cant get my head around this, how can i use a loop to do the exact same thing in this code?

like for the digit[] and bgroup[] array. bgroup[] is a string array that contains 5 digits like (10010). There are 5 of these. what im doing is separating them into separate digits strings. So im basically taking the digit at location x of bgroup[] and setting it to seperate 25 digit[] arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
	digit[0] = bgroup[0].at(0);
	digit[1] = bgroup[0].at(1);
	digit[2] = bgroup[0].at(2);
	digit[3] = bgroup[0].at(3);
	digit[4] = bgroup[0].at(4);

	digit[5] = bgroup[1].at(0);
	digit[6] = bgroup[1].at(1);
	digit[7] = bgroup[1].at(2);
	digit[8] = bgroup[1].at(3);
	digit[9] = bgroup[1].at(4);

	digit[10] = bgroup[2].at(0);
	digit[11] = bgroup[2].at(1);
	digit[12] = bgroup[2].at(2);
	digit[13] = bgroup[2].at(3);
	digit[14] = bgroup[2].at(4);

	digit[15] = bgroup[3].at(0);
	digit[16] = bgroup[3].at(1);
	digit[17] = bgroup[3].at(2);
	digit[18] = bgroup[3].at(3);
	digit[19] = bgroup[3].at(4);

	digit[20] = bgroup[4].at(0);
	digit[21] = bgroup[4].at(1);
	digit[22] = bgroup[4].at(2);
	digit[23] = bgroup[4].at(3);
	digit[24] = bgroup[4].at(4);
Last edited on
1
2
for (int i=0; i<25; i++) 
  digit[i] = bgroup[i/5].at(i%5);


Short enough?
Last edited on
Ah yes, this works. thanks. Is there a website that has many examples of different ways to do array loops ?
Topic archived. No new replies allowed.