C# nested loops ➿

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • C# nested loops tutorial example explained
    #C# #nested #loops
    // nested loops = loops inside of other loops

Комментарии • 42

  • @BroCodez
    @BroCodez  3 года назад +18

    using System;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args)
    {
    // nested loops = loops inside of other loops
    // Uses vary. Used a lot in sorting algorithms
    Console.Write("How many rows?: ");
    int rows = Convert.ToInt32(Console.ReadLine());
    Console.Write("How many columns?: ");
    int columns = Convert.ToInt32(Console.ReadLine());
    Console.Write("What symbol: ");
    String symbol = Console.ReadLine();
    for (int i = 0; i < rows; i++)
    {
    for (int j = 0; j < columns; j++)
    {
    Console.Write(symbol);
    }
    Console.WriteLine();
    }
    Console.ReadKey();
    }
    }
    }

  • @kerb__
    @kerb__ 3 года назад +23

    everything worked but im still not sure why everything worked

    • @kerb__
      @kerb__ 3 года назад +3

      wait i have revisited the for loops video and i think i get it now :D

    • @bogdan1373
      @bogdan1373 Год назад +1

      @@kerb__ this makes the difference between someone who knows or not, the first one continued to want to understand

    • @billythenarwhal1579
      @billythenarwhal1579 7 месяцев назад

      ​@@kerb__so often people explain how but forget that the why is important as well.

  • @EricEO3131
    @EricEO3131 Год назад +6

    This is quite uneasy to understand at first, but for anyone who needs help, here is how it works:
    So, the "nested loop" will do the second loop a set amount of times, in this case, it will do "i" amount of times, which is equivalent to rows, so lets say rows = 4
    so, the second loop will be repeated 4 times, and don't forget the last line of code, which will type "", which is just enter, so it skips to another line
    what does the second loop do? well it writes a "j" amount of symbols, so lets say columns = 5
    so the code basically did the second loop 4 times, and after every time it typed "" so it moves onto the other line of code,which typed the symbol 5 times, then pressed enter 4 times in total, so it actually typed:
    @@@@@
    @@@@@
    @@@@@
    @@@@@

    • @legelf
      @legelf 11 месяцев назад

      i understand this concept pretty well actually after seeing it, the problem is implementing this in different scenarios where it isn't just rows and columns which you have to output...

    • @EricEO3131
      @EricEO3131 11 месяцев назад

      @@legelf Yes, that's true, it can be pretty challenging to implement these in other scenarios, but sometimes it can be pretty straight forward too, it really depends on the problem you're facing

  • @timoneri8812
    @timoneri8812 2 года назад +6

    Very Clear ⬇
    Very Clear ⬇
    Very Clear ✅

  • @PixelPickleWaffle
    @PixelPickleWaffle 4 месяца назад

    Here's a small correction:- The row in this code is actually column and column is rows. So, just rename the column into row and vice versa in the following codes.

    • @Aerionix1
      @Aerionix1 2 месяца назад

      a row is the horizontal series of symbols. The flat line, left to right. A column is the vertical tower of symbols. Top to bottom. He had it right, no correction required. Unless you're referring to someone else's code somewhere in these comments and not the video creator.

  • @SadkGel
    @SadkGel Год назад +1

    why not using char for symbol if you were to use a single character?

  • @אוריברקן-ס9ח
    @אוריברקן-ס9ח Год назад +2

    Why can’t we write
    “WriteLine”
    What does the word “Line” change?

    • @minineji7050
      @minineji7050 Год назад

      I suggest you try it and see what happens, you cant understand code without ever writing some. experimenting is the best way to learn.

    • @The_Ancient_Guardian
      @The_Ancient_Guardian Год назад

      There is a video about that in the begginig of the playlist C# in this channel.

    • @gravecastleofficial
      @gravecastleofficial 8 месяцев назад +1

      Basically, it's literally the next "line" on the screen. So if it's just use "write", all the characters write on the **same line**
      EX:
      {
      ****
      }
      Write"line" () will literally make a **new line** and write on it.
      EX:
      {
      **
      **
      }

  • @joshlukaszewski6015
    @joshlukaszewski6015 Год назад +1

    I'm finally starting to grasp loops but I have one question.
    if i < rows and j < columns
    why wouldn't the result be one less than the user input for each?

    • @sunnywunny
      @sunnywunny Год назад +3

      computers count from 0
      so going to 5 wouldnt be start at 1, 2 3 4 5
      it would be start at 0, 1 2 3 4

  • @wholesomeguy7086
    @wholesomeguy7086 8 месяцев назад

    static void Main(string[] args ) {
    Console.WriteLine("what is the lenth of the square?");
    int lenght = Convert.ToInt32( Console.ReadLine() );
    char symbol = '#';
    for ( int i = 0; i

  • @zesty_chiroptera
    @zesty_chiroptera Год назад +1

    Thanks man! Straight to the point, gotta love it.

  • @hsbsgdgshjsbdjshd3877
    @hsbsgdgshjsbdjshd3877 9 месяцев назад +1

    Thank you so much! I just needed to know the order in which they execute the loops, and you explained it really well

  • @kowshik7941
    @kowshik7941 Год назад

    Thanks for coding with fun brooo, why the hell this page is so underrated!!😟 , even I know these concepts Im obsessed to watch the entire playlist!!!!!!!

  • @spartanranger
    @spartanranger 3 года назад +1

    Thanks for the video my bro

  • @PaCzZoHD
    @PaCzZoHD 2 года назад

    How would I do it if I wanted to write different Symbols in a specific order? Like @&@

    • @bogdan1373
      @bogdan1373 Год назад

      you could create an if statement inside (for j) and if index i, it's odd, to Console.Write("&");

  • @drea7363
    @drea7363 Год назад

    random comment 😃

  • @The_Ancient_Guardian
    @The_Ancient_Guardian Год назад

    ninho de saci.

  • @PektraMom
    @PektraMom Год назад

    what is difference between Console.WriteLine(""); and Console.Write(""); ??

    • @littlegandhi1199
      @littlegandhi1199 Год назад +1

      System.Console.Write() puts more text into the same line.
      WriteLine accepts your input but always issues a new line character. "
      "
      Write you can call multiple times without ending up on the next line down after every little bit of information.
      3
      3
      3
      3
      Or just
      3333

    • @PixelPickleWaffle
      @PixelPickleWaffle 4 месяца назад

      Console.WriteLine("Hello!");
      Console.WriteLine("How are you?");
      Result:-
      Hello!
      How are you?
      Meanwhile, Console.Write("Hello");
      Console.Write("How are you?");
      Result:-
      Hello! How are you?

  • @whitedinamo
    @whitedinamo 2 года назад

    lesson check😇

  • @aliasqar5379
    @aliasqar5379 Год назад

    Thanks

  • @tusharbatra1526
    @tusharbatra1526 Год назад

    I could'nt understand how it worked🤔

    • @ВладМаринов-г8и
      @ВладМаринов-г8и Год назад

      look, we have the outside for loop. only if the conditions are positive for it, the inner for loop works. next, we take one iteration, when i = 0. in this iteration the inner loop code will be done for "columns - 1" times, beginning from 0. for instance, let's take columns = 4. then the symbol will be written 4 times in one row(j = 0, j = 1, j = 2, j = 3), and only then we have Console.WriteLine(); which will skip the rest of our line and the next symbols will be in another row. and this will last for "row - 1" times. for example, if row = 3, then we will have 3 rows ( i = 0, i = 1, i = 2). like that :)

  • @notsaad8900
    @notsaad8900 2 года назад

    Thanks

  • @budderrar5751
    @budderrar5751 Год назад

    noice

  •  3 года назад

    Thanks!

  • @dimassurya3100
    @dimassurya3100 2 года назад +1

    instead of displaying this :
    @@@
    @@@
    @@@
    mine is :
    @
    @
    @
    @
    @
    @

    @
    @
    @ , already follow the script, any help?

    • @benios75m81
      @benios75m81 2 года назад

      use Write() method instead of WriteLine() method in loop with index ""j""

    • @Rahulsingh-theraha
      @Rahulsingh-theraha 2 года назад +5

      check if you have accidently written Console.WriteLine instead of Console.Write