Skip to main content

CS101: Introduction to Computer Science I

Page path
  • Home /
  • Courses /
  • Course Catalog /
  • Computer Science /
  • CS101: Introduction to Computer Science I /
  • Unit 5: Control Structures /
  • 5.4: The 'while' and 'do-while' Loops
Back to 'Unit 5: Control Structures'
  • 5.4: The 'while' and 'do-while' Loops

    • Central Connecticut State University: Bradley Kjell's "Introduction to Computer Science Using Java, Chapter 15: Loops and the While Statement" >

      Please read this chapter. Make sure to click on the arrows to navigate through these webpages. You may also click on the sound icon at the top of the webpage to listen to the MP3. This chapter explains while loop.

      After reading the tutorial, you will understand how a do-while loop works. In a do-while loop, the body of the loop is executed at least one time, whereas in a while loop, the loop may never execute if the loop condition is false. Please read the pages starting with the heading "Bottom Driven Loop" to understand the advantages of this loop.

      At the end of this tutorial, you will understand the difference between while and do-while loops. They both are essentially the same except that the while loop is a pre-test loop and may never execute if the condition is false to begin with. On the other hand, the do-while loop is a post-test loop and always executes at least one time, even if the condition is false.

    • Central Connecticut State University: Bradley Kjell's "Introduction to Computer Science Using Java, Fill in the Blank Exercise For Loops and the While Statement" hide " > URL

      Please complete the fill in the blank exercise. Think of the correct response to fill in the blank for each question, or write your response down on a separate piece of paper. Then, click on the blank to reveal the correct answer.

    • Central Connecticut State University: Bradley Kjell's "Introduction to Computer Science Using Java, Chapter 44: The Daring Do Statement" >

      Please read this chapter. This chapter discusses the do loop, which is a variation of the while loop.

    •  Quiz on the Do Statement

      Attempt this ungraded quiz.

    • Khan Academy: "While Loops in Python" Page

      Please watch this 6-minute lecture. This lecture explains loops by applying them to a simple application, manipulating lists. Though the video uses Python programming language to explain the while loop, the basic concept of the while loop remains the same. The while loop requires a statement in the body of the loop that updates the control variable. In the next section, we will learn about the 'for' loop, which is another implementation of a loop where the control is automatically updated.

Navigation

Art History
Biology
Business Administration
Chemistry
Communication
Economics
English
History
Mathematics

Creative Commons License
© Saylor Academy 2010-2018 except as otherwise noted. Excluding course final exams, content authored by Saylor Academy is available under a Creative Commons Attribution 3.0 Unported license. Third-party materials are the copyright of their respective owners and shared under various licenses. See www.saylor.org/open/licensinginformation for detailed licensing information.

Saylor Academy and Saylor.org® are trade names of the Constitution Foundation, a 501(c)(3) organization through which our educational activities are conducted.

Terms of Use | Privacy Policy