Search code examples
c#unity-game-enginemonodevelopunity3d-2dtools

How to print ********** in a single line by using Debug.Log() in MonoDevelop, a Unity 3D, 2D editor


I want to print

*****
*****
*****
*****
*****

by using a for loop in the console of unity by using Debug.Log() of monoDevelop. Here is my code:

for(int row=1;row<=5;row++)
{
  for(int column=1; column<=5;column++)
     {
         Debug.Log("*");
     }
}

But it shows the output in this way:

*
*
*
*
*
till 25 rows. 

Solution

  • Each call to Debug.Log() is a new line

    If you want to log a line of anything you need to concatenate it into a string, then Log() that string.

    for(int row=1;row<=5;row++)
    {
        string str = "";
        for(int column=1; column<=5;column++)
        {
            str += "*";
        }
        Debug.Log(str);
    }