Share via

C# nested loop help

Anonymous
2022-01-06T08:52:37.127+00:00

I have to create a nested loop that looks like this
(1 representing asterisk and the minus representing the underscore)
1
-1
—1
—-1
——1

I started with
{
for (int i = 0; i< 5, ++i)
{
for (int j=0; j<0;++j)
{
console.write(“*”);
}
Console.writeline(“”);
}

which displays( the one representing the asterisk *)
1
1
1
1
1

i need to incorporate the _ but i don’t know how.
Help

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

P a u l 10,766 Reputation points
2022-01-06T09:02:34.293+00:00

Do you mean something like this?

for (int i = 0; i < 5; ++i) {
    for (int j = 0; j < i; ++j) {
        Console.Write("_");
    }

    Console.WriteLine("*");
}

Produces:

*
_*
__*
___*
____*

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.