break and continue statements | C Programming Tutorial

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • An overview of how to use break and continue statements in C! Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

КОМЕНТАРІ • 15

  • @angelffg
    @angelffg 4 місяці тому

    Great!

  • @mileselim
    @mileselim Місяць тому

    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 4 місяці тому

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

  • @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 Рік тому +1

    00:00

    • @PortfolioCourses
      @PortfolioCourses  Рік тому +1

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