I was asked to explain a bunch of code line by line but I have no the least idea what each line does. Any help would be great but you can skip all the Console.WriteLine's and the { and }. I know those.
using System;
class ForNested
{
static void Main()
{
int i;
int j;
int k;
int x = 8;
int y = -3;
int z = 2;
for (i=5; i%26lt;x; i++)
{
Console.Write("i\n");
for (j=-5; j%26lt;y; j++)
{
Console.Write("j\n");
for(k=0; k%26lt;z; k++)
{
Console.WriteLine("k\n");
}
} Console.ReadLine();
}
}
}
C# Code Explanation?
The six lines after the Main declare six integer variables (i, j, k, x, y, z), three of which are initialized (they are assigned a value).
After that you have three loops. The weird thing is, those loops don't do anything interesting. The first one writes "i i i", the second "j j j" and the third "k k k" (on three seperate lines).
Here's the explanation of the loop: for (i=5; i%26lt;x; i++) means you do what's in the brackets (here it's writing i) until i%26gt;x. i++ means you increment the value of i by one (meaning you add one to i) after each loop. That is, after the first time you wrote i, the value of i will be changed to 6. When i=8 the condition i%26lt;x will not be respected anymore and you will get of the loop without writing i.
To write the actual value of i instead of just writing "i" you should replace Console.Write("ï\n") by Console.Write ("{0}",i);
The "\n" is just used for presentation, it means you go to the next line after you've written your information.
And the Console.ReadLine will just leave the window open so that you can see what's written in it.
Hope this helps! Ask again if there's anything else you don't understand
Here's a great tutorial on C# if you need: http://www.functionx.com/csharp/Lesson01...
Reply:well it does math. substitues letetters like i, j with numbers. writes results on text line.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment