Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested for statement in c# visual studio express doesn't work 1

Status
Not open for further replies.

Panchovia

Programmer
May 6, 2010
48
0
0
CW
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pattern_1
{
class Program
{
static void Main(string[] args)
{


for ( int i = 1; i <= 10; i++) ;

for (int j = 1; j <= 10; j++) ;

Console.Write("x");
Console.ReadLine();
}
}
}

This code should write a square block of x on the screen it doesn't what should be added to the code ?
 
If it does not do what you want it to do, exactly what does it do?

I don't know much about C, but if C is like FoxPro and most other languages, you don't have your FORs nested properly.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
You definitely do not have your FORs nested correctly.

Here is a sample of nested FORs that produce 10 rows 10 characters long:


[pre] for (int i = 1; i <= 10; i++)
{
for (int j = 1; j <= 10; j++)
{
//Output character;
WRITESTR("X");
}
//New line;
EOL();
}
[/pre]

Change your code to something similar to this and it should work.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
You might also want to go back and review this thread that you started last year. If you had remembered, you would not have needed to ask a second time.


.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
Hi mmerlinn.com

If you don't program in C# you mustn't answer my question WRITESTR doesn't exist in Ms visual studio C# thank anyway for your help.
 
Hi mmerlinn

I am quiet impressed on your comments but you as a programmer you don'know anything of this nguage C is not same as c++ and non behave the same,so I would appreciated that you don't comment on my code because from your comment I can conclude that you don't know anything about ms visual studio 2010 c# so keep your comments tour yourself.
 

Panchovia,
Here is another way to write the same code but this also doesn't output the correct instructions.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Patern1_1
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++) ;//Nested for loop
{
Console.Write("x");
Console.Write("x",j);
}
Console.Write("\n");
}
Console.ReadLine();
}

}
}

output should be;
ten rows of x horizontally
ten rows of x vertically

 
Panchovia
Problem solved here is the correct code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Patern1_1
{
class Program
{
static void Main(string[] args)
{
int i, j;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++) //Nested for loop
{
Console.Write("x");

}
Console.Write("\n");
}

Console.ReadLine();
}

}
}
 
.


Panchovia:

I told you that I did not know C.

I never said WRITESTR() nor EOL() was part of C. I never said the example was in any form of C.

The following code (NOT C) is another example of how to nest FOR loops to get the results that you desired.

[pre]FOR i = 1 TO 10
FOR j = 1 TO 10
PRINT "X"​
NEXT​
PRINT CHR(13)​
NEXT
[/pre]

This is EXACTLY the structure that you adapted in your final code.

I gave you an EXAMPLE of how to nest for loops and told you to do something SIMILAR in your code. I never said that the example had ANYTHING to do with C.

Your FINAL code is a near copy of the EXACT structure I outlined for you.

Next time you need help, even if I know the answer, LIKE I DID THIS TIME, I will not waste my time replying since you seem to think that ONLY people that know C can help you. You are wrong and the proof lies in the fact that your final code is almost an exact copy of the STRUCTURE I suggested to solve your dilemma. I detest trying to help ungrateful people who do not appreciate my help.

Apparently you wanted someone to write YOUR code for you for FREE for a SECOND time. Not me. I gave an example of the structure you needed leaving it up to you to do what you are PAID to do - ADAPT my SAMPLE code to your problem at hand.



.

mmerlinn


Poor people do not hire employees. If you soak the rich, who are you going to work for?

"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond
 
I have to agree with mmerlinn: the question author (Panchovia) appears to be exceedingly ungrateful for what to me (as a C# (and other languages) programmer) seems to be very relevant advice; it puts me in mind of petulant children.

... and as xwb points out, the question should have been asked in the C# forum.
 
Rest easy guys. If Panchovia was any sort of C, C#, C++, VC programmer himself, he would have stepped through his own code using the quite useful debugger. He would then have noticed that his code structure of:

for ( int i = 1; i <= 10; i++) ;
for (int j = 1; j <= 10; j++) ;
Console.Write("x");
Console.ReadLine();

would have looped through the first 'for' 10 times, the next 'for' 10 times, then produced a single "x" which is clearly in his write statement. It's really too bad an inexperienced beginner like him has the balls to be that judgmental in this forum.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top