KnowledgeBoat Logo

Computer Science

What are the four elements of a while loop in Python?

Python Control Flow

30 Likes

Answer

The four elements of a while loop in Python are:

  1. Initialization Expressions — It initializes the loop control variable and it is given outside the while loop before the beginning of the loop.
  2. Test Expression — If its truth value is true then the loop-body gets executed otherwise not.
  3. The Body of the Loop — It is the set of statements that are executed repeatedly in loop.
  4. Update Expressions — It updates the value of loop control variable and it is given inside the while loop.

Answered By

16 Likes


Related Questions