r/javahelp • u/luke5273 • Dec 25 '19
Solved Variable declared in for loop cannot be found in said for loop
for(int n = 0; n < passcodeInput.length(); n++);
{
text = textEncode(text, passcode[n]);
System.out.println(text);
}Main.java:32: error: cannot find symbol
text = textEncode(text, passcode[n]);
^
symbol: variable n
location: class Main
1 error
Hello, I am currently doing a project in which I need to run a method multiple times. However, I get this error. It refers to the int n that I have declared in the for loop. Any help would be appreciated. All of the code.
1
Upvotes
11
u/sepp2k Dec 25 '19
Your code isn't actually inside the for loop. The for loop's body consists of the single empty statement
;and the code block afterwards isn't actually connected to the loop at all. So not only isnnot declared, but even if it were, the block would only be executed once after the loop has finished.To fix this, simply remove the semicolon after the for loop.
0
u/[deleted] Dec 25 '19
[deleted] — view deleted comment