0

Can someone explain why is this code have 6 outputs?

num1=2 while (num1 !=0): num2=3 while (num2 !=0): print('hello') num2 =num2 -1 num1 = num1 -1

21st Jul 2022, 7:52 PM
Vinuka Fernandopulle
Vinuka Fernandopulle - avatar
2 Antworten
+ 4
Vinuka Fernandopulle num1 = 2 while (num1 != 0): num2 = 3 while (num2 != 0): print('hello') num2 = num2 - 1 num1 = num1 - 1 Inner loop will work 3 times because num2 = 3 Outer loop will work 2 times because num1 = 2 So "hello" will be print 6 times
21st Jul 2022, 8:00 PM
A͢J
A͢J - avatar
+ 1
3*2. Num2 is 3, you go 3 Times tho the loop and print Hello, Num1 is 2 and's above the former loop, also you Set 2 Times the value of Num2 to 3 and print 3 Times Hello. While 2!=0 num2 = 3 While num2 != 0 print('hello') num2-- ... While 1!=0 num2 = 3 While num2 != 0 print('hello') num2--
21st Jul 2022, 8:03 PM
Felix Alcor
Felix Alcor - avatar