int count;
for(count=10;count<=1;count--)
{
Console.write("Hello");
}

Why Doesnt appear nothing when I run this code?? have logic for me...

Dani AI

Generated

Short summary and practical fix tying the thread together: correctly pointed out that the loop never ran because the loop condition was false at the start, and correctly reminded that C# is case-sensitive. Below is a minimal, working console example that shows a safe pattern and keeps the window open so you can see output.

using System;

class Program
{
    static void Main()
    {
        for (int i = 1; i <= 10; i++)
        {
            Console.WriteLine("Hello");
        }

        Console.WriteLine("Finished. Press any key to exit.");
        Console.ReadKey();
    }
}

Key things to check when a loop prints nothing:

  • Execution order: the for statement runs the initializer, then checks the condition before the first iteration. If that test is false, the body never executes.
  • Match the comparison and the step direction (use ++ for ascending, -- for descending). An inverted comparison will make the loop skip entirely.
  • Watch for a stray semicolon after the for(...) header (for(...);) — that creates an empty loop and the following block runs once after the loop.
  • Casing matters: Console.Write / Console.WriteLine must be capitalized and using System; is needed for Console.
  • If output flashes and disappears when you run from an IDE, run with Ctrl+F5 or add Console.ReadKey() to pause.

If the loop still surprises you, add a debug print or breakpoint inside the loop to inspect the loop variable and condition before and during the run. This often makes the mistake obvious faster than guessing.

Recommended Answers

All 3 Replies

int count;
for(count=10;count>=1;count--)
{
Console.write("Hello");
}

Try it now. Looks like you were just confused about how the for loop works. The second statement means 'as long as it is true' but 10 is never <= than 1.

Regards

Hi,

Write is with capital letter like Console.Write("Hello"); . Remember that C# is case-sensitive.


Regards,
Camilo

int count;
for(count=10;count>=1;count--)
{
Console.write("Hello");
}

Try it now. Looks like you were just confused about how the for loop works. The second statement means 'as long as it is true' but 10 is never <= than 1.

Regards

thx..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.