none
Incrementing within for loops RRS feed

  • Question

  • I'm looking to increment such that the first set of values in my for loop remains unchanged by the increment, I think there must be some tidyer way of doing it than to simply subtract the incremental amount outside my loop. Any advise would be welcome, here's my code:

                   

    namespace ForIncrementing
    {
        class Program
        {
            static void Main(string[] args)
            {
                int jaboat = 10;
                int jaboat2 = jaboat - 6;            //this seems like a bad way to solve the problem
                for (int i = 0; i < 3; i++)
                {
                    Line LX = new Line();
                    LX.Y1 = 10;
                    LX.Y2 = LX.Y1 + 20;

                    LX.X1 = jaboat2 +=6;             //want to make this increment after the first instance
                    LX.X2 = LX.X1;

                    Console.WriteLine($"{LX.X1} {LX.X2}");
                    Console.WriteLine($"{LX.Y1} {LX.Y2}");
                }
            }
        }
    }

    Thanks

    Sunday, January 6, 2019 11:42 AM

Answers

All replies