jadyn
Uploaded by
20 SLIDES
360 VUES
200LIKES

Understanding Count-Controlled Loops: Initialization, Testing, and Updating Variables

DESCRIPTION

This chapter covers count-controlled loops, which include an initialization of the loop control variable, a condition to test if the loop should continue running, and an update of the control variable in each iteration. Using examples, we demonstrate how to declare a loop variable, initialize it, and execute repeated actions in Java. A sample code illustrates the structure and behavior of a count-controlled loop, along with outputs that show the current count at each iteration, culminating in a final output indicating completion.

1 / 20

Télécharger la présentation

Understanding Count-Controlled Loops: Initialization, Testing, and Updating Variables

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
SlideServe
Audio
Live Player
Audio Wave
Play slide audio to activate visualizer