While Loops - Intro to Computer Science

Sdílet
Vložit
  • čas přidán 21. 07. 2024
  • This video is part of an online course, Intro to Computer Science. Check out the course here: www.udacity.com/course/cs101.

Komentáře • 112

  • @yesserlabidi7831
    @yesserlabidi7831 Před 4 lety +70

    this is the best explanation ever of while loop !! thank you sir !

    • @otekanonso7059
      @otekanonso7059 Před 2 lety

      I swear this is the best explanation I have seen for a while loop I really understand it so now I can write a code with this understanding.

  • @shazrakhalid1641
    @shazrakhalid1641 Před 3 lety +13

    I WAS STUCK ON THIS FOREVER!!! THANK YOU!!!

  • @suomynona7261
    @suomynona7261 Před 3 lety +1

    OMG you explained this so well! Thank you! I couldn’t wrap my head around WHY is was doing that. I knew how to control it by memory alone but not by understanding. 🙏

  • @sayedibrahim6131
    @sayedibrahim6131 Před 3 lety +3

    one of the best explanations ever for while loop 🔁 ❤️ thanks

  • @brucewayne3141
    @brucewayne3141 Před 3 lety +5

    This is so much better than the way my instructor told us!

  • @serdarkaraca9172
    @serdarkaraca9172 Před 3 lety +69

    The first "i" is equal to 0 (i = 0). But, before it gets printed it goes through the equation of i = i + 1 so the first i that gets printed is 1.
    Now at the i = 8 mark it goes through the equation i = i+1 (before getting printed) and gets printed out as 9. Then 9 != 10 goes through and gets printed as (the last number) 10. Then when 10 goes through it becomes 10 != 10 WHICH IS FALSE so ends the while loop.
    as printed (1,2,3,4,5,6,7,8,9,10). D - "Print out the numbers from 1 to 10"

  • @avivpizanty8384
    @avivpizanty8384 Před 3 lety

    what pen did you use? and where you wrote it?

  • @marctkocz1478
    @marctkocz1478 Před 8 měsíci

    10/10
    Really nice explained👌🏽
    Thanks a lot

  • @bblife167
    @bblife167 Před 9 měsíci

    i love you so much you saved me 100%. thanks a lot fr. youre a real one

  • @3372PHILIP
    @3372PHILIP Před 6 lety

    Excellent explaination keep it up

  • @doubleq1223
    @doubleq1223 Před 5 lety +6

    came here for loops brother, was bamboozled

  • @stutteringcris468
    @stutteringcris468 Před 2 lety

    i keep getting "invalid syntax"
    and the 3 keeps getting highlighted in the top "python 3.9.0"

  • @demetrik8642
    @demetrik8642 Před 3 lety +1

    Absolutely beautiful

  • @aybin.v.k9562
    @aybin.v.k9562 Před 7 lety +6

    Thanks for comparing While and if.......
    can we use colon instead of parenthesis in WHILE ???
    Semicolon after printf() is missing

    • @damiaobrito6431
      @damiaobrito6431 Před 6 lety

      AYBIN. V. K it will always depend on what programming language you are using
      EDIT:
      as I can see, his code sample is based on Python

  • @rashulmehul5779
    @rashulmehul5779 Před 6 lety +4

    We want more videos of this loop programs

  • @indiaupbanda
    @indiaupbanda Před 3 lety

    Simplest way.... Thank you so much

  • @mlittleprogramming780
    @mlittleprogramming780 Před 4 lety +1

    Great video!

  • @user-ue2ti5ny3w
    @user-ue2ti5ny3w Před 6 měsíci

    very good explanation

  • @artursweden3653
    @artursweden3653 Před rokem

    A perfect explanation

  • @isaloy_2375
    @isaloy_2375 Před 3 lety

    it does print 1 to 9 doesn't it ?

  • @venkatraman_padmanaban
    @venkatraman_padmanaban Před 5 lety +10

    Print from 1 to 10 values and comes out of the loop

  • @abubekirlenty8854
    @abubekirlenty8854 Před rokem

    well done! thank you!

  • @stephenkite399
    @stephenkite399 Před 4 lety

    Ok so I just got started in coding. My problem is i don’t understand where to execute my code. Is it supposed to work in the console? I’m using google chrome and I could really use someone’s help.

  • @abdullah3lshe77i8
    @abdullah3lshe77i8 Před 5 lety +1

    THANK YOU SO MUCH BRO

  • @harryneuhoff9115
    @harryneuhoff9115 Před rokem

    What language is this in??

  • @YoshevElazarMikael
    @YoshevElazarMikael Před rokem

    Thank you sir!!!

  • @artistalreem1180
    @artistalreem1180 Před 5 lety

    heloo any one can help me to solve this program
    Write a C++ programme that reads a sequence of integers terminated by zero value then finds the percentage of the negative numbers and the percentage of the positive number in the sequence. The programme output is as shown: :
    Enter a sequence of in integers terminated by zero
    6 -7 -8 10 -12 14 15 2 -6
    the percentage of negative numbers is 44.4
    the percentage of positive numbers is 55.6

    • @ripndipp
      @ripndipp Před 4 lety

      let a = "Hello, ";
      let b = "World";
      let c = a + b
      console.log(c);
      thank me later this is the best i could do.

  • @keeshaholsey1973
    @keeshaholsey1973 Před 6 lety

    love it

  • @YoshevElazarMikael
    @YoshevElazarMikael Před rokem

    I was given an example:
    n = 5
    while n > 0:
    n = n - 1
    print(n)
    4
    3
    2
    1
    0
    From this result: it is clear that the layout in the body is wrong; the 'print()' statement should go first.

  • @layanalkhatib6486
    @layanalkhatib6486 Před 4 lety

    i used Small Basic program and my answer was : {print out the numbers from 0 to 9}.

  • @minitaz3167
    @minitaz3167 Před 6 lety +5

    Option d is correct

  • @HamzaShahzad1
    @HamzaShahzad1 Před 4 lety +4

    produces an error, there is no parentheses around the print statement

  • @azeemsiddiqui3853
    @azeemsiddiqui3853 Před 4 lety +2

    It will produce error since the test expression is not true. So the block will also not be executed. Numbers are only incrementing if the test expression is true only.

  • @keeshaholsey1973
    @keeshaholsey1973 Před 6 lety

    so cool

  • @vishalkatraj
    @vishalkatraj Před 3 lety

    thank you

  • @nomteemzee3540
    @nomteemzee3540 Před 2 lety

    what happens if you remove the condition of i= i +1

    • @m26k29
      @m26k29 Před 2 lety

      infintiiy loop will go on and prints 0 for infintiiy

    • @m26k29
      @m26k29 Před rokem

      @هه‍هههههههههههههه مصرى

  • @Septix
    @Septix Před 6 lety +12

    Actual answer is 1-10: Option 4. The reason it stops at 10 instead of 9 now is because it's checking... is i = 10 yet? once it says YES then we exit the loop. The loop terminates RIGHT there because it reached its goal which is 10. Only part i don't get is why it does not start at 0 to 10... why 1.

    • @cobain1228
      @cobain1228 Před 6 lety +3

      It starts at 0, but then in the block i=0+1, so i has a new value of 1, and finally print i that is equal to 1.

    • @williamngwaihow
      @williamngwaihow Před 6 lety +2

      i = 0
      while(i != 10):
      i = i + 1
      print("i =", i)
      print("Exit Loop")
      Phython

    • @stannisbarracuda5693
      @stannisbarracuda5693 Před 6 lety +6

      it writes from zero and ends at 9 it would write 10 if the parameter was

    • @jamesclarity1077
      @jamesclarity1077 Před 5 lety

      @@stannisbarracuda5693 exactly that's what I was thinking... != In Python to the best of my knowledge is does NOT equal....so should have exited.... However my Python emulator is showing 10 too.

    • @jamesclarity1077
      @jamesclarity1077 Před 5 lety

      Scratch that....just gave this more thought think a little longer...

  • @denvd.b8559
    @denvd.b8559 Před 7 lety +2

    there is no semilcolon in while( parenthesis)😐😐😐😐

    • @damiaobrito6431
      @damiaobrito6431 Před 6 lety

      diwakar bangera there is in Python programming language

  • @anushkapandey8588
    @anushkapandey8588 Před 3 lety +4

    Is it
    3) 1 to 9?
    Cause it'll only print after the initial value of i (0) is added to the operation *i = i + 1*
    And it also satisfies the condition that i ≠ 10

    • @JackM12345100
      @JackM12345100 Před 3 lety

      Remember that when the final loop begins when i=9 the condition is met (i is less than 10). Then the i is changed to 10 before i is printed, so this program would print 1 - 10.

  • @HJ-jl5pj
    @HJ-jl5pj Před 7 lety +2

    is the answer the third option?

    • @bellagutierrez5194
      @bellagutierrez5194 Před 5 lety

      H J it will print numbers 1-10 then exit the loop. Nine is not equivalent to ten so it will go through the loop one more time

  • @abhisekchetri3136
    @abhisekchetri3136 Před 5 lety

    X=1
    Whilex

  • @rajendranjeganesh5529
    @rajendranjeganesh5529 Před 3 lety

    The answer is for your quiz =
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Thank you from Sri Lanka❤❤❤

  • @ericplayer4203
    @ericplayer4203 Před 7 lety +2

    it is an error right?

  • @WJGSix
    @WJGSix Před 5 lety +1

    Ok so who had the right answer? I felt like it was 1 to 10

  • @chidex968
    @chidex968 Před 5 lety +1

    option 2

  • @amf2702
    @amf2702 Před 6 lety +9

    The answer is that the program prints out the numbers from 1 to 10

    • @benzox9940
      @benzox9940 Před 4 lety

      Im stuck on this, Do you know why? And whats the difference when the addition follows the print?

    • @amf2702
      @amf2702 Před 4 lety +2

      @@benzox9940 bruh I forgot how it works, this was two years ago..

    • @dazza1080
      @dazza1080 Před 4 lety

      😂😂😂😂

    • @sphollo1
      @sphollo1 Před 3 lety +2

      @@benzox9940 its all about the sequence, having the i + 1 before the print command added 1 to the i value prior to it printing, so it started printing numbers starting with 1 then restarted the while loop and printed the numbers 1 to 10. If the i + 1 was after the print command it would have printed the number 0 then added 1 to i and restarted the while loop and printed all numbers from 0-10.

  • @floatiee
    @floatiee Před rokem

    D - Print out the numbers from 1 to 10

  • @LukeJosiahNadal
    @LukeJosiahNadal Před 6 lety +8

    i = 0
    while i is not equal to 10
    i = i +1
    print i
    is i not equal to 10? ( i = 0)
    Yes, the program ends until it keeps adding the value 1 to the variable i until it defies the while condition, repeating the while loop 9 times until "not equal to 10" becomes "equal to 10". Thank me later

    • @iztirabk5135
      @iztirabk5135 Před 4 lety +1

      true, same point noted here

    • @shivagaming5001
      @shivagaming5001 Před 3 lety

      Word I noticed that but I'm just getting into it so I think it's still helpful. I would say this is an example of debugging because how he wrote it the program would print before any addition

    • @YoshevElazarMikael
      @YoshevElazarMikael Před rokem

      If 'i' is < 10, why would it print? While 'i' is less than 10, then the programme prints a value.

  • @billygruff6541
    @billygruff6541 Před 5 lety +2

    0-9 ... sorry I took so long to comment.. I'm still on dial-up

  • @iliyasgangaram3134
    @iliyasgangaram3134 Před 3 lety

    it prints 1 to 10

  • @nofilkhan6743
    @nofilkhan6743 Před 5 lety

    Answer is 1 to 10

  • @hanaasleem1261
    @hanaasleem1261 Před 3 lety

    from 0 to 9 (b)

  • @AhmedSedik
    @AhmedSedik Před 5 lety

    prints from 0-10

  • @Tomtastic7
    @Tomtastic7 Před 5 lety +2

    The answer is Run forever

    • @AS-od4um
      @AS-od4um Před 5 lety +2

      Techie Tom no if the value of i is 10
      So it will be 10 ! = 10 the statement will be false

  • @walitouseef9751
    @walitouseef9751 Před 6 lety +1

    Maybe runs forever

    • @phuturephunk
      @phuturephunk Před 6 lety

      In his last example (the question at the end), it will print 1 through 10 and then exit the loop.

    • @mohammadkhader1759
      @mohammadkhader1759 Před 5 lety

      @@phuturephunk because it was asked to print all numpers that are less than ten , this question is diffrant , it askes for all numpers that does not equal ten ( 1 2 3 4 5 6 7 8 9 _ 11 12 13 ....)

  • @devika389
    @devika389 Před 3 lety

    writing with a pen ......but not really..........my heads' spinning

  • @vincenthan5980
    @vincenthan5980 Před 8 lety +1

    nb

  • @mohammadkhader1759
    @mohammadkhader1759 Před 5 lety +2

    it will run forever , because its going to print all numpers but ten , >>>>>>1 2 3 4 5 6 7 8 9 11 12 13 .....

    • @TheAbsoluteSir
      @TheAbsoluteSir Před 4 lety

      Wrong, you misunderstand how iteration works.

    • @jess6241
      @jess6241 Před 3 lety

      doesnt it stop once y does not equal 10?

  • @hydos3807
    @hydos3807 Před 3 lety

    For while loop or statement click on the link czcams.com/video/D7j1YWsC45I/video.html

  • @MojeZycieWSkrocie
    @MojeZycieWSkrocie Před 4 lety

    try i = 11 lol

  • @felixnyarko7828
    @felixnyarko7828 Před 5 lety +4

    Answer is 1-10: Option 4

    • @TheAbsoluteSir
      @TheAbsoluteSir Před 4 lety +1

      Why would it not be B) 0-9 ?
      The previous while loop went from 0 through 9.

  • @ilikespaghetti2170
    @ilikespaghetti2170 Před 4 lety +1

    1-10

  • @karolstevenvillacarillo1036

    hmmmmmm

  • @devika389
    @devika389 Před 3 lety

    writing technique is soo distracting...............

    • @ScholarDCareerSolutions
      @ScholarDCareerSolutions Před 3 lety

      Try watching this video to understand loops.. czcams.com/video/0XamI1W-wzE/video.html

  • @aryamangurha
    @aryamangurha Před 5 lety +3

    lol u just made it unnecessarily complecated...
    For printing *"Ben"* 10 times in a loop:
    10 FOR i = 1 to 10
    20 PRINT "Ben"
    30 NEXT i
    40 END

  • @ameanasaur
    @ameanasaur Před 4 lety

    Great video but your hands distract from everything. We don’t need to see your hand writing it, we need to see the code. Also, use white font on a black background like anyone who stares at a screen for 8+ hours a day does, can’t watch this after a day of work + school.

  • @cancan740
    @cancan740 Před 4 lety

    very good explanation