What will be the output for the following code?i=0while(i<3): j=0 while(j<3): print(i,j,end=" ") j+=1 print()
Question
What will be the output for the following code?
i=0
while(i<3):
j=0
while(j<3):
print(i,j,end=" ")
j+=1
print()
Solution
The output of the given code will be:
0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2
Here's the step by step explanation:
- The outer loop runs three times as i ranges from 0 to 2.
- For each iteration of the outer loop, the inner loop also runs three times as j ranges from 0 to 2.
- In each iteration of the inner loop, the current values of i and j are printed, followed by a space.
- After each iteration of the outer loop, a newline is printed. This is why each set of three pairs is on a new line.
Similar Questions
Study the following program:i = 0while i < 3: print(i) i += 1 else: print(0)
What will be the output of the following program?while i < 20: print(i) i += 1
What is the output of the following few lines of code?1234x=0while(x<2): print(x) x=x+1 1 point010120134
What is the output of the following code snippet?int i = 0;do { if (i == 3) continue; System.out.print(i + " "); i++;} while (i < 5);
What is the output of the following code? for i in range(3): print(i) else: print("Loop finished")
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.