Great question! :-) It's because in the loop body we increment i and THEN output i. So if i == 9, then i < 10 so the loop body will run. Then we increment i by 1 so i now 10, and then we output i and 10 outputs. Then we check the loop condition and i is not < 10 so the loop stops at that point. Hopefully that explanation helps! :-)
because of the increment i think, it actually stopped by 9 but since we have i++ which is equal to i + 1, we added the value i which is equal to 9 (i = 9 ) then we add the value of 9 to 1 then we get 10
I wrote on Python this While True: Line = Input (‘>done’) If line == ‘done’: Break Print (line) Print (“Done!”) But the problem I’m experiencing is that the loop doesn’t end so I can change anything so I want to know if I did something wrong and how I should write it
It's difficult to tell what's wrong because things like spacing and capitalization will matter a lot for this sort of problem, and the code you've posted doesn't seem valid (e.g. a while loop with a capital W, is there really Line and line or is that just a capitalization issue because it's very important the same variable name is used for input and for checking the input, etc.). The indentation of the code is also very important and it's difficult to tell if the indentation is correct here.
@@PortfolioCourses the app indents for me it’s just I wrote it different here but now that you mention it I’ll have a go at making sure I write it out with the capitals in
@@PortfolioCourses while True: line = input('hello') if line == 'done': break print (line) print ('Done!') i wrote it like this but when i deindent it'll produce the input but then the input i placed in at the start will keep looping how would you write it out cuz i really am not sure where i went wrong.
For me the loop stops when I enter done. It does not print out the line entered each time though. If you wanted to do that you would need to have print(line) at the bottom, and indented at the same level as when you have line = input('hello'). I'm not sure why it's not working for you but I suspect it has something to do with indentation within your IDE.
turn on auto save
quick question, since 'i' is < 10, why did 10 print? shouldn't it stop at 9.
Great question! :-) It's because in the loop body we increment i and THEN output i. So if i == 9, then i < 10 so the loop body will run. Then we increment i by 1 so i now 10, and then we output i and 10 outputs. Then we check the loop condition and i is not < 10 so the loop stops at that point. Hopefully that explanation helps! :-)
because of the increment i think, it actually stopped by 9 but since we have i++ which is equal to i + 1, we added the value i which is equal to 9 (i = 9 ) then we add the value of 9 to 1 then we get 10
@@PortfolioCourses is it same if I wrote in the while conditions
While ( i
❤❤❤❤❤❤
Great!
I wrote on Python this
While True:
Line = Input (‘>done’)
If line == ‘done’:
Break
Print (line)
Print (“Done!”)
But the problem I’m experiencing is that the loop doesn’t end so I can change anything so I want to know if I did something wrong and how I should write it
It's difficult to tell what's wrong because things like spacing and capitalization will matter a lot for this sort of problem, and the code you've posted doesn't seem valid (e.g. a while loop with a capital W, is there really Line and line or is that just a capitalization issue because it's very important the same variable name is used for input and for checking the input, etc.). The indentation of the code is also very important and it's difficult to tell if the indentation is correct here.
@@PortfolioCourses the app indents for me it’s just I wrote it different here but now that you mention it I’ll have a go at making sure I write it out with the capitals in
@@PortfolioCourses
while True:
line = input('hello')
if line == 'done':
break
print (line)
print ('Done!')
i wrote it like this but when i deindent it'll produce the input but then the input i placed in at the start will keep looping how would you write it out cuz i really am not sure where i went wrong.
For me the loop stops when I enter done. It does not print out the line entered each time though. If you wanted to do that you would need to have print(line) at the bottom, and indented at the same level as when you have line = input('hello'). I'm not sure why it's not working for you but I suspect it has something to do with indentation within your IDE.
@@PortfolioCourses thanks for the advice
00:00
Is there something off at that point in the video? :-)