+ 2
I have a question about while loop
count = 0 while count < 7 print (count) count = count + 1 Output: 0 1 2 3 4 5 6 Why does it print 0 as well? Does it print the count when it's 0 first then proceeds to print the new count ?
5 odpowiedzi
+ 4
You defined count as 0.
You then printed count.
Then added 1 and printed count each time you did until you hit 7.
If you would have defined count as 3, youd get:
3
4
5
6
+ 5
Why did you print count first and then adding 1 with the initial value?
+ 4
It prints 0 because you are printing before incrementing count ,so obviously it's initial value which is zero is printed first
+ 3
You increase count with 'count = count + 1' AFTER you print its value with 'print (count)'
+ 3
Look at your code carefully ...
When it is printing the 1st time the value of count it is 0 cause after that the value is increasing by 1...so obviously it will be 0....
If you dont want to print 0 then write the
count = count + 1 statement before the print statement or set the value of count 1....
.
Happy Coding mam