How to display a certain string out of array depending on a number?

Hello, I am trying to create a week system Monday through Sunday and I have these names in an array of string and I want them to be displayed accordingly to the number of that day. However, whenever I try to create a loop for it, something goes wrong.

public TextMeshProUGUI dayText;
public string[] dayName;

public int countDays;
public int dayNo;
bool test;
// Start is called before the first frame update
void Start()
{
    dayName[0] = "Monday";
    dayName[1] = "Tuesday";
    dayName[2] = "Wednesday";
    dayName[3] = "Thursday";
    dayName[4] = "Friday";
    dayName[5] = "Saturday";
    dayName[6] = "Sunday";
    dayNo = 1;
}

// Update is called once per frame
void Update()
{
    CountDays();
}
public void CountDays()
{
    //TO DO 
    //DISPLAY NAME OF THE DAY ACCORDING TO THE NUMBER
    if (Input.GetKeyDown(KeyCode.A))
    {
        test = true;
    }
    if (test)
    {
        for (int i = 0; i < 7; i++)
        {
            dayText.text = dayName*;*

print(i);
}
}
}
As you can see in CountDays() function I was trying to put a condition to break out of the loop but immediately when I press “A” it changes from Monday to Sunday and I want it to be Monday → Tuesday → Wednesday etc.
Please and thank you in advance for any help

Hi! Instead of doing your for loop, try simply incrementing the dayNo variable and printing that out:

void Update()
{
    if (Input.GetKeyDown(KeyCode.A))
    {
        dayNo += 1;

        dayText.text = dayName[dayNo];
        Debug.Log(dayName[dayNo]);
    }
}

The problem was that you were going through all 7 days in one click instead of one at a time.

You’ll notice the above code will run into an error once this number goes past 7, but you can loop it around with the fancy modulo (%) operator:

dayNo = (dayNo + 1) % 7;

Hope this helps :smiley: