C# nested loops ➿

preview_player
Показать описание
C# nested loops tutorial example explained

#C# #nested #loops

// nested loops = loops inside of other loops
Рекомендации по теме
Комментарии
Автор

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 =

Console.Write("How many columns?: ");
int columns =

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

BroCodez
Автор

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

hsbsgdgshjsbdjshd
Автор

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

zesty_chiroptera
Автор

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

kowshik
Автор

Very Clear ⬇
Very Clear ⬇
Very Clear ✅

timoneri
Автор

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:




EricEO
Автор

everything worked but im still not sure why everything worked

kerb__
Автор

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?

joshlukaszewski
Автор

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

SadkGel
Автор

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

PaCzZoHD
Автор

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.

PixelPickleWaffle
Автор

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

ymrfonc
Автор

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

PektraMom
Автор

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<lenght; i++)
{
for ( int j = 0; j<lenght; j++ )
{
Console.Write(symbol);

}
Console.WriteLine();
}

























Console.ReadKey();
}

wholesomeguy
Автор

I could'nt understand how it worked🤔

tusharbatra
Автор

instead of displaying this :
@@@
@@@
@@@

mine is :
@
@
@



@
@
@


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

dimassurya