1 / 20

Chapter 5 File Objects and Looping Statements (Count-controlled Loop Example only)

Chapter 5 File Objects and Looping Statements (Count-controlled Loop Example only). Count-controlled loops contain. An initialization of the loop control variable An expression to test for continuing the loop

jadyn
Download Presentation

Chapter 5 File Objects and Looping Statements (Count-controlled Loop Example only)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 File Objects and LoopingStatements (Count-controlled Loop Example only)

  2. Count-controlled loops contain • An initialization of the loop control variable • An expression to test for continuing the loop • An update of the loop control variable to be executed within each iteration of the body

  3. Count-controlled Pattern int loopCount; // Declare loop variable loopCount = 1; // Initialize loop variable while (loopCount <= 10) // Test expression { . // Repeated actions . . loopCount = loopCount++; // Update loop variable }

  4. Count-controlled Example int count; // Declare loop variable count = 1; // Initialize loop variable while (count <= 4) // Test expression { // Repeated action System.out.println(“count is “ + count); count ++;// Update loop variable } System.out.println(“Done”);

  5. count Count-controlled loop int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println(“Done”); OUTPUT

  6. count 1 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT

  7. count 1 int count; count = 1; while ( count <= 4 ) { TRUE System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT

  8. count 1 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1

  9. count 2 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1

  10. count 2 int count; count = 1; while ( count <= 4 ) { TRUE System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1

  11. count 2 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2

  12. count 3 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2

  13. count 3 int count; count = 1; while ( count <= 4 ) { TRUE System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2

  14. count 3 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3

  15. count 4 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3

  16. count 4 int count; count = 1; while ( count <= 4 ) { TRUE System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3

  17. count 4 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3 count is 4

  18. count 5 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3 count is 4

  19. count 5 int count; count = 1; while ( count <= 4 ) { FALSE System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3 count is 4

  20. count 5 int count; count = 1; while ( count <= 4 ) { System.out.println ( “count is “ + count ); count++; } System.out.println( “Done” ); OUTPUT count is 1 count is 2 count is 3 count is 4 Done

More Related