Below code is resulting in "Avoid declaring or assigning variables in a loop that are not dependent on the loop condition". (According to the coding best practices)
private void testingLoop() {
String var[]= {"java", "code", "review"};
String arr[] = new String[1];
for(String i : var)
{
arr[0] = i.concat("Script");
}
System.out.println("The result is: " +arr[0]);
}
Why is it considered as a bad practice when we assign variables inside a loop ? any solution to overcome this problem ?
Note: My intention was only to show the for loop, so don't consider much about the purpose of the code.