增加变量值直到满足条件C#

时间:2017-08-01 09:31:55

标签: c#

无法在这里找出好的逻辑我需要增加计数器的值直到满足条件。但它说这个程序在这里什么都不做

int num;
int ctr = 3;
reqID = browser.Div(Find.ByClass("gwt-Label WNII") && Find.ByIndex(ctr)).OuterText;
bool isNumeric = int.TryParse(reqID, out num);
bool isTR = reqID.Contains("T_R_");

do { ctr++; }
while (isTR == true || isNumeric == true);
{
    reqID = browser.Div(Find.ByClass("gwt-Label WNII") && Find.ByIndex(ctr)).OuterText;
}

解析此页面

https://hpe.wd5.myworkdayjobs.com/en-US/Jobsathpe/job/CBC01---Aruba-Cork-CBC01/Pricing-Specialist_1006905-3

https://hpe.wd5.myworkdayjobs.com/en-US/Jobsathpe/job/RYA01---Riyadh-Al-Faisaliah-Tower-RYA01/Portfolio-Sales-Specialist_1006892-1

查看它有多少次“gwt-Label WNII”类的迭代

2 个答案:

答案 0 :(得分:1)

您不会更改循环中任何条件的变量。因此,循环将永远不会开始或永远不会完成

您可能需要这样订购:

int num;
int ctr = 3;

bool isTR = false;
bool IsNumeric = false;

do
{
    reqID = browser.Div(Find.ByClass("gwt-Label WNII") && Find.ByIndex(ctr)).OuterText;
    if(reqID != null)
    {
        isNumeric = int.TryParse(reqID, out num);
        isTR = reqID.Contains("T_R_");
    }
    ctr++;
}
while (!isTR && !isNumeric);

do参考:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/do

答案 1 :(得分:1)

在上下文中将你的bool声明在你之外并在里面修改它:

int num;
int ctr = 3;
bool isNumeric = true;
bool isTR = true;

do
{
   reqID = browser.Div(Find.ByClass("gwt-Label WNII") && 
   Find.ByIndex(ctr)).OuterText;
   isNumeric = int.TryParse(reqID, out num);
   isTR = reqID.Contains("T_R_");
   ctr++;
}
while (isTR == true || isNumeric == true);