Skip to content
Loading
for loop problem
  • Hi,
    Try this
    for(int i=1;i<=9;i++)
    {
       if (i % 3 == 0)
          Response.Write("a");
       else
          Response.Write(i);
       Response.Write("
    ");
    }
    0
  • Tapan Patel
    Here is how you can do using Linq.
    1. Enumerable.Range(1,10).ToList().ForEach(i=>{if(i%3==0) Console.WriteLine('a');else Console.WriteLine(i);});
    Please mark it as an answer if it addresses the issue.
    0
  • Hi Lee,
    Use modulo operator for number position like,
    class Program
    {
    static void Main()
    {
    int position = 3;
    string importCharacter = "a";
    int n = 9;
    for (int i = 1; i <=n; i++)
    {
    if (i % position != 0)
    Console.WriteLine(i);
    else
    Console.WriteLine(importCharacter);
    }
    Console.ReadLine();
    }
    }
    0
  • Midhun Tp
    Hi,
    Try this code -
    for (int i = 1; i < 10; i++)
    {
    if (i % 3 != 0)
    Console.WriteLine(i);
    else
    Console.WriteLine("a");
    }
    0