© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
9 replies
js

foreach loop index error

foreach (string toppings in toppingsArray)
{
    if (count <= toppingsArray.Length)
    {
        string topping = toppingsArray[count];
        _names.Add(topping);
        string price = toppingsArray[count + 1];
        _prices.Add(price);
        count = count + 2;
    }
    else if (count > toppingsArray.Length)
    {
        break;
    }
}
foreach (string toppings in toppingsArray)
{
    if (count <= toppingsArray.Length)
    {
        string topping = toppingsArray[count];
        _names.Add(topping);
        string price = toppingsArray[count + 1];
        _prices.Add(price);
        count = count + 2;
    }
    else if (count > toppingsArray.Length)
    {
        break;
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Foreach loop
C#CC# / help
4y ago
❔ problems with foreach loop
C#CC# / help
3y ago
✅ Arrays and Foreach Loop - Beginner
C#CC# / help
3y ago