Jump to content

Explain looping

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
digitalbeef

digitalbeef

    Newbie

  • Members
  • PipPip
  • 13 posts
A user posted this a little while ago, and I have never used private class before. Can somebody explain how exactly this program works for me? Mainly just the code in private and how it directly relates to the remainder of the program. Thx


using System;


public class Getstngvowels

{

    public static void Main()

    {

        while (true)

        {

            Console.Write("Enter a vowel or ! to exit: ");

            string input = Console.ReadLine();


            if (input == "!")

            {

                break;

            }

            else if (IsVowel(input))

            {

                // a vowel was entered

                Console.WriteLine("OK");

                break;

            }

            else

            {

                Console.WriteLine("Do you know what a vowel is?! you crap load! Try again.");

            }

        }

    }


    private static bool IsVowel(string s)

    {

        if (s.Length != 1)

            return false;


        s = s.ToLowerInvariant();

        if (s == "a" || (s == "e") || (s == "i") || (s == "o") || (s == "u"))

        {

            return true;

        }

        else

        {

            return false;

        }

    }

}



#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
It's not a private class, the public class has a private function, basically the user using the class cannot access the function only the class itself can.

It looks like if a vowel is entered it breaks the loop, if not it asks again.