Showing the path of a projectile I'm trying to dive deeper into C#, and so I've been experimenting with some code. I'm creating a console application that shows the path of a projectile depending on the angle, and it works great! You can check it out here actually. It's not perfect, but I like it.

Is there a better way to use my for loops? I'm using 3 inside eachother, and I'm not sure if that should be an issue. If you could take a look at the code in the link, it'd be great.

I realized my code might not have shown up. The code snippet won't work if you try to do it as you're missing a couple functions I've devised, but you should be able to get the idea just by looking at it.

using System.IO;
using System;
using System.Threading;
class Program
{

static void Main()
{
    Console.Clear();

    DoArc();
}

static void DoArc() {

            int tempVal = 0;
            string displayLine = "";
    //HERE
    for(int a = 0; a &lt; 90; a+= 2) {

        Console.Clear();
        //HERE
        for(int y = 0; y &lt; 16; y++) {
            //HERE
            for(int x = 0; x &lt; 40; x++) {
                tempVal = Mathf.RoundToInt(Physics.HeightAtPoint(x, a, 15f, 0));
                tempVal = Mathf.Clamp(tempVal, 0, 16);

                if(Mathf.CloseTo(16 - y, tempVal, 1)) 
                displayLine += " X";
                else
                displayLine += " .";

            }
        Console.WriteLine(displayLine);
        displayLine = "";
        }
        Console.WriteLine("Angle: " + a);
        Thread.Sleep(500);

    }
}
}
I don't see anything particularly wrong with the loops themselves, but, as far as coding style goes:


tempVal and displayLine should be declared as close as possible to the place where they're first used.
the values returned by Math.RoundToInt and Mathf.Clamp don't seem to have anything in common, so they should be assigned to different variables. Don't reuse tempVal for different and unrelated things.
tempVal, x, y and a should be given more meaningful names.
You should use a StringBuilder to build strings, instead of using string concatenation.
Your indentation is all over the place.
In C#, it is common practice to put the opening bracket { on its own line - although one could argue that this is a matter of personal preference and doesn't really matter as long as you're consistent throughout the codebase.

for(int y = 0; y &lt; 16; y++)
{
    var sb = new StringBuilder();

    //HERE
    for(int x = 0; x &lt; 40; x++)
    {
        int height = Mathf.RoundToInt(Physics.HeightAtPoint(x, a, 15f, 0));
        int clamp = Mathf.Clamp(height, 0, 16);

        if(Mathf.CloseTo(16 - y, clamp, 1)) 
            sb.Append(" X");
        else
            sb.Append(" .");

    }
    Console.WriteLine(sb.ToString());
}