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(); } } }
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: @@@@@ @@@@@ @@@@@ @@@@@
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...
@@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
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!!!!!!!
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?
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: { ** ** }
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.
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.
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
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?
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 :)
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
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();
}
}
}
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:
@@@@@
@@@@@
@@@@@
@@@@@
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...
@@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
Thank you so much! I just needed to know the order in which they execute the loops, and you explained it really well
LOOOOOOOOOOOOOL
Thanks man! Straight to the point, gotta love it.
everything worked but im still not sure why everything worked
wait i have revisited the for loops video and i think i get it now :D
@@kerb__ this makes the difference between someone who knows or not, the first one continued to want to understand
@@kerb__so often people explain how but forget that the why is important as well.
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!!!!!!!
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?
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
Very Clear ⬇
Very Clear ⬇
Very Clear ✅
Thanks for the video my bro
why not using char for symbol if you were to use a single character?
Why can’t we write
“WriteLine”
What does the word “Line” change?
I suggest you try it and see what happens, you cant understand code without ever writing some. experimenting is the best way to learn.
There is a video about that in the begginig of the playlist C# in this channel.
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:
{
**
**
}
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.
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.
Thanks!
what is difference between Console.WriteLine(""); and Console.Write(""); ??
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
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?
Thanks
Thanks
How would I do it if I wanted to write different Symbols in a specific order? Like @&@
you could create an if statement inside (for j) and if index i, it's odd, to Console.Write("&");
I could'nt understand how it worked🤔
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 :)
instead of displaying this :
@@@
@@@
@@@
mine is :
@
@
@
@
@
@
@
@
@ , already follow the script, any help?
use Write() method instead of WriteLine() method in loop with index ""j""
check if you have accidently written Console.WriteLine instead of Console.Write
lesson check😇
noice
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
ninho de saci.
loopy
commenting
random comment 😃