tute_lab_week7.pdf - Tutorial and Laboratories Week 7 Tutorial While Loop The while loop repeatedly executes an indented block of statements as long as

tute_lab_week7.pdf - Tutorial and Laboratories Week 7...

This preview shows page 1 - 2 out of 5 pages.

Tutorial and Laboratories Week 7 Tutorial While Loop The while loop repeatedly executes an indented block of statements as long as a certain condition is met. A while loop has the form The line beginning with while is called the header of the loop , the condition in the header is called the continuation condition of the loop, the indented block of code is called the body of the loop, and each execution of the body is called a pass through the loop. The continuation condition is a boolean expression that evaluates to either True or False. Each line in the block of statements should be indented the same distance to the right. This physical indentation of the block tells the interpreter where the block starts and stops. When Python encounters a while loop, it first checks the truth value of the continuation condition. If the condition evaluates to False, Python skips over the body of the loop and continues with the line (if any) after the loop. If the continuation condition evaluates to True, the body of the loop is executed. After each pass through the loop, Python rechecks the condition and proceeds accordingly. That is, the body will be continually executed until the continuation condition evaluates to False. For Loop The for loop is used to iterate through a sequence of values. The general form of a for loop is: where sequence might be an arithmetic progression of numbers, a string, a list, a tuple, or a file object.
Image of page 1

Subscribe to view the full document.

Image of page 2
  • Three '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes