- 2

Get the value out of a loop ?

If I have a loop: for(i=0; i!=5 ; i++) and the value 5 is reached how can I access the x value after the loop? To use it later on?

12th Sep 2016, 12:48 AM
Prinz Leguan
Prinz Leguan - avatar
5 ответов
+ 2
Declare the variable before the for loop: int variable = 0; for ( int i = 0; i < 5; i++ ) { variable += i; } System.out.println( variable );
12th Sep 2016, 1:06 AM
Liam
Liam - avatar
0
But wouldn't it be consuming changing this variable each time if I had a loop that would go like up to 8000?
12th Sep 2016, 1:11 AM
Prinz Leguan
Prinz Leguan - avatar
0
I'm not too sure I understand your question then, could you give me an example of what you want to do?
12th Sep 2016, 1:31 AM
Liam
Liam - avatar
0
I want to do a little brute force show program. First you enter 4 digits then the program goes up to your value and then shows you what your password is.
12th Sep 2016, 1:36 AM
Prinz Leguan
Prinz Leguan - avatar
0
its just that you cant start a loop nowhere so least possibiltiy is to keep it zero
13th Sep 2016, 7:15 AM
Milin Parekh
Milin Parekh - avatar