Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:02:46+00:00 2026-06-06T14:02:46+00:00

Morning, simple stupid question. I have found post with similar issues but after reading

  • 0

Morning, simple stupid question. I have found post with similar issues but after reading through it does not solve my error.

Return value from For loop

Can't get a return value from a foreach loop inside a method

The methods: meth1 meth2 ect….all return a value but at the moment I am getting the error

“Error 1 ‘Proj5.Program.meth1(int)’: not all code paths return a value” for each meth method.

My logical guess is its not seeing the value within the loop?? …

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Proj5
{
class Program
{
    static void Main()
    {
        for (int i = 1; i < 101; i++)
        {
            if (i == 3 || 0 == (i % 3) || 0 == (i % 5) || i == 5)
            {
                Console.Write(meth1(i));
                Console.Write(meth2(i));
                Console.Write(meth3(i));
                Console.Write(meth4(i));
            }
            else
            {
                Console.Write(TheInt(i));
            }
        }
        Console.ReadLine();
    }

    static string meth1(int i)
    {
        string f = "fuzz";

        if (i == 3)
        {
            return f;
        }
    }
    static string meth2(int i)
    {
        string f = "fuzz";

        if (0 == (i % 3))
        {
            return f;
        }
    }
    static string meth3(int i)
    {
        string b = "buzz";

        if (i == 5)
        {
            return b;
        }

    }
    static string meth4(int i)
    {
        string b = "buzz";

        if (0 == (i % 5))
        {
            return b;
        }
    }
    static int TheInt(int i)
    {
        return i;
    }

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:02:48+00:00Added an answer on June 6, 2026 at 2:02 pm

    You say your method should return a string, but if i<>3, you don’t say what should be returned.
    Method 2 and 3 have the same problem, by the way (and 4 also).
    I won’t speak about method TheInt, which is… funny 😉

    Correction

    static string meth1(int i)
        {
            string f = "fuzz";
    
            if (i == 3)
            {
                return f;
            }
            return null;//add a "default" return, null or string.Empty
        }
    

    or shorter

    static string meth1(int i) {
        return (i == 3) ? "fuzz" : null/*or string.Empty*/;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty simple question but I'm having a rough morning it seems. I have the
Morning all, I have a simple question that I could do with some help
Simple one this morning, but causing me issues and can't seem to find any
Good Morning, I have a really simple script that works fine on everything but
this must be very simple but it's monday morning.. I have a label and
Good morning SO, So I have a simple question I can't seem to find
Good morning in my timezone. Those are simple questions , i just do not
After fighting all morning, I got the handshake to work but now I'm stuck
Maybe I need more coffee this morning but here goes... I have a very
Good morning / afternoon, I have a very simple MS Access DB and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.