C do while loop 🤸‍♂️

Поділитися
Вставка
  • Опубліковано 7 лис 2024

КОМЕНТАРІ • 44

  • @BroCodez
    @BroCodez  3 роки тому +50

    #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 # ?

  • @cadyneisfeld540
    @cadyneisfeld540 2 роки тому +7

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

  • @adrianedge7975
    @adrianedge7975 2 роки тому +19

    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

  • @reecetrahan6169
    @reecetrahan6169 Рік тому +6

    Can you do multiple whiles? Like 4 conditions?

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

      just use && between conditions

    • @resurging6306
      @resurging6306 Рік тому +2

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

  • @normalhether5806
    @normalhether5806 5 місяців тому +1

    i didnt understand this in css50 so i came here thanks

  • @akbarkim
    @akbarkim 6 місяців тому +1

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

  • @Fiaz_at_everything
    @Fiaz_at_everything Рік тому +2

    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?

    • @iamethan2153
      @iamethan2153 Місяць тому +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 4 місяці тому

    great

  • @nhano7712
    @nhano7712 5 місяців тому

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

    • @pedro-3339
      @pedro-3339 3 місяці тому

      yes, but it's easier for begginers to understand

  • @البنوتة-ك3خ
    @البنوتة-ك3خ 6 місяців тому

    😍😍😍😍😍😍😍

  • @ryanalnaser914
    @ryanalnaser914 2 роки тому +1

    whatever anything before or after or I do or did

  • @AIDZ__
    @AIDZ__ Рік тому +2

    I dont get it again.... goddamnit

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

    what is printf?

    • @markoforgiarini1242
      @markoforgiarini1242 Рік тому

      input

    • @danny0.o
      @danny0.o 7 місяців тому

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

  • @tefooooo1948
    @tefooooo1948 2 роки тому +3

    How did we get 15 at the end?

  • @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 :)

  • @WOLF_XXX0
    @WOLF_XXX0 8 місяців тому

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

    • @danny0.o
      @danny0.o 7 місяців тому

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

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

    • @gymknight4085
      @gymknight4085 27 днів тому

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