Home > Net >  How to make a for loop through
How to make a for loop through

Time:05-27

Public static void Main ()
{
String s="USA";
Console. WriteLine (DetectCapitalUse (s));
The Console. ReadKey ();
}
Public static bool DetectCapitalUse (string word)
{

For (int I=0; i {
If (System. Text. RegularExpressions. Regex. Matches (word [0]. ToString (), "[a-z]"). The Count & gt; 0 & amp; & System. Text. RegularExpressions. Regex Matches (word [0]. ToString (), "[a-z]"). The Count & gt; 0)
{
return true;

}
Else if (System. Text. RegularExpressions.. Regex Matches (word [I] the ToString (), "[a-z]"). The Count & gt; 0)
{
return true;

}
Else if (System. Text. RegularExpressions.. Regex Matches (word [0]. ToString (), "[a-z]"). The Count & gt; 0)
{
return true;

}
The else
{
return false;

}


}
return true;
}

CodePudding user response:

Only left a U judgment, how can let the for loop through, let him put the string of all value judgment again

CodePudding user response:

Return to continue

CodePudding user response:

The meaning of the return is returned to the method of the caller

Your writing said as long as there is a loop ends meet conditions

CodePudding user response:

This code horrible...
Since in the regular, direct
 string s="USA"; 
Var result=Regex. IsMatch (s, "[a-z]");//determine whether s contains uppercase letters
//var result=! Regex. IsMatch (s, "[^ a-z]");//does s composed of capital letters all

, you will be able to determine whether s contains uppercase letters,

According to your thoughts and see loop back problems, first of all, the assumption that all you need to determine is composed by the capital letters, so the end result should be
Every word [I] must be capital letters, in the traversal, to determine the each character, and the results are logic and operation;
Can also be in the loop, set the capital letters to jump out of condition
 for (... ) {
If (the capital) return false;
}
return true;

CodePudding user response:

In addition, the loop structure, the end of the cycle, into the next cycle, with the continue;
Return directly to the end of the current method and return (so certainly out of the current method of loop structure)

CodePudding user response:

Do you want on earth

CodePudding user response:

We don't know you want to do in logic, because we don't know what you exactly want IEnumerable (don't do logic, simply the result of each character), or to Any (Any one meet), or to All (meet)

CodePudding user response:

refer to the second floor taocl2000 response:
return to continue
return value write

CodePudding user response:

refer to 6th floor qq_30335331 response:
what do you want to do
is a method I want to write about in our thinking

CodePudding user response:

reference Eason0807 reply: 3/f
return means to return to the method of the caller

Your writing said as long as there is a loop ends meet conditions
just to satisfy a branch ends, but oh judgements all the characters in the string,

CodePudding user response:

Why the method didn't go out, because of the for loop, as long as there is a way to meet the conditions, will return true; Return means to jump out of the for loop, jump out of the way, will return the value of the as DetectCapitalUse this method returns a value,
If this method can finish all the data in the for go, that means a branch not eligible for loop,

CodePudding user response:

refer to 7th floor wanghui0380 response:
we don't know you want to do in logic, because we don't know what you exactly want IEnumerable (don't do logic, simply the result of each character), or to Any (Any one meet), or to All (meet)

All the letters are capitalized, such as "USA",
All letters in the words are not capitalized, such as "leetcode,"
If the words not only contain one letter, only capitalize the first letter, such as "Google",
Meet one of them

CodePudding user response:

X
refer to 4th floor - I - n reply:
this code horrible...
Since in the regular, direct
 string s="USA"; 
Var result=Regex. IsMatch (s, "[a-z]");//determine whether s contains uppercase letters
//var result=! Regex. IsMatch (s, "[^ a-z]");//does s composed of capital letters all

, you will be able to determine whether s contains uppercase letters,

According to your thoughts and see loop back problems, first of all, the assumption that all you need to determine is composed by the capital letters, so the end result should be
Every word [I] must be capital letters, in the traversal, to determine the each character, and the results are logic and operation;
Can also be in the loop, set the capital letters to jump out of condition
 for (... ) {
If (the capital) return false;
}
return true;

All the letters are capitalized, such as "USA",
All letters in the words are not capitalized, such as "leetcode,"
If the words not only contain one letter, only capitalize the first letter, such as "Google",
This is three judgment conditions

CodePudding user response:

11 references platforms-as-a-service plus response:
why the method didn't go out, because of the for loop, as long as there is a way to meet the conditions, will return true; Return means to jump out of the for loop, jump out of the way, will return the value of the as DetectCapitalUse this method returns a value,
If this method can finish all the data in the for go, that means a branch not eligible for loop,

All the letters are capitalized, such as "USA",
All letters in the words are not capitalized, such as "leetcode,"
If the words not only contain one letter, only capitalize the first letter, such as "Google",
Meet one of them

CodePudding user response:

refer to the eighth floor LiCcCcCcccCcc response:
Quote: refer to the second floor taocl2000 response:
return to continue
return value write what

Don't know what are you going to do, but if you want to walk the circulation, and want to have a return value, then you can declare a variable in cycle in vitro, to modify a variable's value in the loop body, at the end of the loop body, again before returning to your definition of a variable's value,

CodePudding user response:



reference 15 floor taocl2000 response:
Quote: refer to the eighth floor LiCcCcCcccCcc response:
Quote: refer to the second floor taocl2000 response:
return to continue
return value write what

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related