C# nested loops ➿

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • C# nested loops tutorial example explained
    #C# #nested #loops
    // nested loops = loops inside of other loops

КОМЕНТАРІ • 44

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

    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();
    }
    }
    }

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

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

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

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

  • @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.

  • @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!!!!!!!

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

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

    Very Clear ⬇
    Very Clear ⬇
    Very Clear ✅

  • @spartanranger
    @spartanranger 3 роки тому +1

    Thanks for the video my bro

  • @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 9 місяців тому +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:
      {
      **
      **
      }

  • @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.

  •  3 роки тому

    Thanks!

  • @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?

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

    Thanks

  • @notsaad8900
    @notsaad8900 2 роки тому

    Thanks

  • @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("&");

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

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

  • @whitedinamo
    @whitedinamo 2 роки тому

    lesson check😇

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

    noice

  • @wholesomeguy7086
    @wholesomeguy7086 9 місяців тому

    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

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

    ninho de saci.

  • @definitelynotchris4776
    @definitelynotchris4776 5 днів тому

    loopy

  • @simik4830
    @simik4830 6 днів тому

    commenting

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

    random comment 😃