+ 1

Possibilities of loops

I have a for loop and I want to access the individual result like the first number is 10 and the second is 20 and third is 40... Is it possible to access individual result of this loop in my code? If so how? https://code.sololearn.com/cBeFka6Pro3r/?ref=app

27th Sep 2017, 6:13 PM
Sibusiso Mbambo
4 Answers
+ 4
The variable i allows you to access the results. If you want each result to be stored individually, perhaps use an array. Example/ int[] array = new int[100]; // fill array with appropriate values for(int i = 10, index = 0; i < 10000; i*=2) array[index++] = i; Now you can do as you please with the array!
27th Sep 2017, 6:17 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Sry for the late response, but: The code I wrote works fine for me. Make sure it is exact and there are no extra words. Perhaps try writing your own similar thing if it is not working. The idea was just to store all the numbers into an array, that way you can do whatever you want with any of those numbers. As a random guess, did you happen to forget the comma between: "i = 10" and "index = 0"? Should be: "int i = 10, index = 0"
28th Sep 2017, 3:15 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
@Rrestoring faith I'm getting an error with that code you written "illegal character"
27th Sep 2017, 8:29 PM
Sibusiso Mbambo
0
Thank you for taking your time to answer my question. It working fine now.
29th Sep 2017, 8:08 AM
Sibusiso Mbambo