C#C
C#4y ago
p.av

for loop returning nothing

using System;
using static System.Console;
 
namespace ColouredTriangles
{
    class Program
    {
        static void Main(string[] args)
        {
 
            WriteLine("Enter the first line");
            string line = ReadLine();
 
            while (line.Length != 1) // for loop constantly outputting ""
            {
                string temp = "";
                for (int i = line.Length-2; i == 0; i--)
                {
 
                    if (line[i] == line[i + 1])
                    {
                        temp += line[i];
                    }
 
                    else if (line[i].ToString() == "R")
                    {
                        if (line[i + 1].ToString() == "G")
                        {
                            temp += "B";
                        }
                        else
                        {
                            temp += "G";
                        }
                    }
 
                    else if (line[i].ToString() == "G")
                    {
                        if (line[i + 1].ToString() == "R")
                        {
                            temp += "B";
                        }
                        else
                        {
                            temp += "R";
                        }
                    }
 
                    else
                    {
                        if (line[i + 1].ToString() == "R")
                        {
                            temp += "G";
                        }
                        else
                        {
                            temp += "B";
                        }
                    }
                }
 
                WriteLine(temp);
                line = temp;
 
            }
 
 
 
        }
    }
}
Was this page helpful?