Robotics & Artificial Intelligence

How many times will the following loop execute? What will be the output?

count = 0
while count < 3:
    print("Hello")
    count += 1

Python Control Flow

1 Like

Answer

Number of times the loop will execute: 3 times

Output
Hello
Hello
Hello
Explanation
  • The variable count is initialised to 0. The while loop runs as long as count < 3 is true.
  • Each time the loop executes, "Hello" is printed and the value of count is increased by 1.
  • When count becomes 3, the condition count < 3 becomes false and the loop stops.

Answered By

2 Likes


Related Questions