Looping Statements Interview Questions

    Question 1Python While Loop Execution

    What will be the output of the following code?

    x = 0 while x < 3: print(x, end=" ") x += 1

    Question 2Python For Loop with Range

    What will this code output?

    for i in range(2, 5): print(i, end=" ")

    Question 3Python Step in Range

    What is the output?

    for i in range(1, 10, 3): print(i, end=" ")

    Question 4Python Break Statement

    What will be the output?

    for i in range(5): if i == 3: break print(i, end=" ")

    Question 5Python Continue Statement

    What is the output?

    for i in range(5): if i == 2: continue print(i, end=" ")

    Question 6Python Else with Loop

    What will be the output?

    for i in range(3): print(i, end=" ") else: print("Done")

    Question 7Python Infinite While Loop

    Which of the following will create an infinite loop?

    Question 8Python Nested Loop

    What will be the output?

    for i in range(2): for j in range(2): print(i, j, end=" ")

    Question 9Python Iterating Over String

    What will this code output?

    for ch in "Hi": print(ch, end="-")

    Question 10Python Range with Negative Step

    What will be the output?

    for i in range(5, 0, -2): print(i, end=" ")