Difference between revisions of "CheckWordIsValid"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 
Line 16: Line 16:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
The code starts by setting the variable ValidWord to false and the variable count to 0.
 
The code starts by setting the variable ValidWord to false and the variable count to 0.
The next line says while the count is less than the total number of allowed words & not a valid word then it sees if the word is in the allowed words and if it is then the count is incremented by 1, else it will return ValidWord.
+
The next line says while the count is less than the total number of allowed words & not a valid word then it sees if the word is in the allowed words and if it is then the count is incremented by 1, then return ValidWord which will say if the word is valid or not by true and false.

Latest revision as of 14:59, 14 November 2017

        private static bool CheckWordIsValid(string Word, List<string> AllowedWords)
        {
            bool ValidWord = false;
            int Count = 0;
            while (Count < AllowedWords.Count && !ValidWord)
            {
                if (AllowedWords[Count] == Word)
                {
                    ValidWord = true;
                }
                Count++;
            }
            return ValidWord;
        }

The code starts by setting the variable ValidWord to false and the variable count to 0. The next line says while the count is less than the total number of allowed words & not a valid word then it sees if the word is in the allowed words and if it is then the count is incremented by 1, then return ValidWord which will say if the word is valid or not by true and false.