I am very new to programming and I have an assignment, but I am not asking for the solution. I just want to understand what is being asked. Our instructor presented two codes using a break and continue statement. He stated that both methods are bad programming practices. Which I think I know the answer to that but what he wants us to do is redo the code or improve it. Here id the code
public class Break
{
public staic void main( String args[] )
{
int count;
for (count = 1; count <= 10; count++ )
{
if (count == 5 )
break;
System.out.print( "%d ", count );
}
System.out.printf(c"\nBroke out of loop at number: %d\n", count );
}
}
How can you improve this? The only thing I can think of is the variable was declared a value inside the for loop, and if the variable changes it can create an infinite loop. So my solution was to declare the variable as a static variable to create a value that could never be changed and could not create an infinite loop. Was that the one being asked?