break and continue statements | C Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น • 16

  • @mileselim
    @mileselim 5 หลายเดือนก่อน

    turn on auto save

  • @Chigo-nr8jg
    @Chigo-nr8jg ปีที่แล้ว +1

    quick question, since 'i' is < 10, why did 10 print? shouldn't it stop at 9.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +3

      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! :-)

    • @IrohaNatsumeMyBeloved
      @IrohaNatsumeMyBeloved ปีที่แล้ว +1

      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

    • @Salamanca-joro
      @Salamanca-joro 8 หลายเดือนก่อน

      ​@@PortfolioCourses is it same if I wrote in the while conditions
      While ( i

  • @kingofgamer1102
    @kingofgamer1102 2 หลายเดือนก่อน

    ❤❤❤❤❤❤

  • @angelffg
    @angelffg 8 หลายเดือนก่อน

    Great!

  • @IliosAdamos
    @IliosAdamos ปีที่แล้ว

    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

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      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.

    • @IliosAdamos
      @IliosAdamos ปีที่แล้ว

      @@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

    • @IliosAdamos
      @IliosAdamos ปีที่แล้ว

      @@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.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      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.

    • @IliosAdamos
      @IliosAdamos ปีที่แล้ว

      @@PortfolioCourses thanks for the advice

  • @nasscim
    @nasscim 2 ปีที่แล้ว +1

    00:00

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Is there something off at that point in the video? :-)