Discuss the following:
Q: This figure shows an example of using a command in Java called break and continue. I somewhat disagree with the use of these commands in this way. I consider it bad form as does much of the industry. Just because a command is there does not mean you have to use it!
Why this is bad form and provide a snippet of code that shows a better way to code the loops in this example.
I am actually using Jcreator to look at this code. You can either use Jcreator or Netbeans java program to do this one if you choose:
// Fig. 5.12: BreakTest.java
// break statement exiting a for statement.
Public class BreakTest
{
Public static void main( String args[] )
{
int count; // control variable also used after loop terminates
for ( count = 1; count <= 10; count++ ) // loop 10 times
{
if ( count == 5 ) // if count is 5,
break;
System.out.printf( "%d ", count );
} // end for
System.out.printf( "nBroke out of loop at count = %dn", count );
} // end main
} // end class BreakTest