C do while loop 🤸‍♂️

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.พ. 2025
  • C do while loop tutorial example explained
    #C #do #loop

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

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

    #include
    int main()
    {
    // while loop = checks a condition, THEN executes a block of code if condition is true
    // do while loop = always executes a block of code once, THEN checks a condition
    int number = 0;
    int sum = 0;
    do{
    printf("Enter a # above 0: ");
    scanf("%d", &number);
    if(number > 0)
    {
    sum += number;
    }
    }while(number > 0);

    printf("sum: %d", sum);

    return 0;
    }

    • @KaraSub2.0
      @KaraSub2.0 ปีที่แล้ว +1

      Why number is wrote as # ?

    • @xercz74934
      @xercz74934 23 วันที่ผ่านมา +1

      @@KaraSub2.0 idk if you're still looking for an answer but i guess it's a short form

  • @cadyneisfeld540
    @cadyneisfeld540 2 ปีที่แล้ว +8

    You just gained a new sub... You're the best

  • @adrianedge7975
    @adrianedge7975 2 ปีที่แล้ว +24

    i was trying to research how this worked for an hour and a half now until this video, thank you

    • @adrianedge7975
      @adrianedge7975 2 ปีที่แล้ว

      in my head i was thinking as long as the while was true the code executed but if false it didn't, not that if false it didnt REPEAT. aka it executes once regardless. Thanks again

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

    Thank you! ❤

  • @normalhether5806
    @normalhether5806 8 หลายเดือนก่อน +2

    i didnt understand this in css50 so i came here thanks

  • @reecetrahan6169
    @reecetrahan6169 2 ปีที่แล้ว +8

    Can you do multiple whiles? Like 4 conditions?

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

      just use && between conditions

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

      @@ntsd7509 or || if you want "or"

  • @mysteriousstranger1084
    @mysteriousstranger1084 23 วันที่ผ่านมา

    Thx bro, came to my rescue once again.

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

    Man I wish you were my professor.

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

    Why do we need the if? You already said while i greater 0 so you could just put the equation anyways?

    • @iamethan4444
      @iamethan4444 4 หลายเดือนก่อน +1

      Because a negative number that would force exit the loop would affect sum's value, so you only want to sum the positive entries.

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

    great

  • @AIDZ__
    @AIDZ__ ปีที่แล้ว +4

    I dont get it again.... goddamnit

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

    whatever anything before or after or I do or did

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

    Tenkyu😈😈😈😈😈

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

    Isn't condition (if(number >0)) redundant?

    • @pixewtorto
      @pixewtorto 6 หลายเดือนก่อน

      yes, but it's easier for begginers to understand

  • @البنوتة-ك3خ
    @البنوتة-ك3خ 9 หลายเดือนก่อน

    😍😍😍😍😍😍😍

  • @TONY_GEORGE-25
    @TONY_GEORGE-25 11 หลายเดือนก่อน

    why is the sum 15 at the end , can someone explain me pls..

    • @danny0.o
      @danny0.o 10 หลายเดือนก่อน

      im prolly abit late but when he entered the values (1, 2, 3, 4, 5) it all added up together because of the 'sum', basically each value got added which added up to 15
      1+2+3+4+5 = 15

    • @SuryaSurya-sc1ri
      @SuryaSurya-sc1ri 6 หลายเดือนก่อน

      @@danny0.o Can you explain sum +=number;

    • @gymknight4085
      @gymknight4085 4 หลายเดือนก่อน

      ​@@SuryaSurya-sc1riit is basically same with sum=sum + number (it is just shorter form)

  • @AlanSanchez-w5o
    @AlanSanchez-w5o 2 หลายเดือนก่อน

    I love you

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

    what is printf?

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

      input

    • @danny0.o
      @danny0.o 10 หลายเดือนก่อน

      'printf' is to output to the terminal window...basically its like displaying something to the user

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

    How did we get 15 at the end?

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

      Oh yea yea i got it xd

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

      1+2+3+4+5 = 15 sum value

  • @akbarkim
    @akbarkim 9 หลายเดือนก่อน +1

    ОД ДУШИ БРАТ
    ❤‍🩹

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

    خ

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

      ğ

    • @lalmi6150
      @lalmi6150 3 ปีที่แล้ว

      @@SpicaSuzuki what?

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

      @@lalmi6150 My goals are beyond your understanding.
      And üİşçöı

    • @lalmi6150
      @lalmi6150 3 ปีที่แล้ว

      @@SpicaSuzuki you are cool girl, i liked your type

    • @SpicaSuzuki
      @SpicaSuzuki 3 ปีที่แล้ว

      @@lalmi6150 thanks :)