在C#中的if else if和else语句之间循环 [英] Looping in between the if else if and else statement in C#
本文介绍了在C#中的if else if和else语句之间循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试自动化网站
我的方案是
Hi All,
I am trying to do automation a website
My scenario is
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if(webBrowser1.Url = newSystem.Uri"https://xyz.aspx",System.UriKind.Absolute)
{
//do something
}
else if webBrowser1.Url=newSystem.Uri"https://xyz.aspx",System.UriKind.Absolute)
{
//do something
}
else
{
//do something
}
现在我想要下面
Now I want like below
if(webBrowser1.Url = newSystem.Uri"https://xyz.aspx",System.UriKind.Absolute)
{
//do something
}
for(int i=0; i<= 3; I++)
{
else if webBrowser1.Url=newSystem.Uri"https://xyz.aspx",System.UriKind.Absolute)
{
//do something
}
else
{
//do something
}
}
}
我该怎么做才能帮助
感谢All
我尝试过:
在if else if和else语句之间循环在C#
How can I make this please help
Thanks to All
What I have tried:
Looping in between the if else if and else statement in C#
推荐答案
if(webBrowser1.Url = newSystem.Uri"https://xyz.aspx",System.UriKind.Absolute)
{
//do something (the original do something)
for(int i=0; i<= 3; I++)
{
//do something
}
}
else
{
for(int i=0; i<= 3; I++)
{
//do something
}
}
您不能将else
应用于任何类型的循环构造 -for
,foreach
,do
,或while
- 因为它们不是条件语句,尽管它包含条件表达式。在循环的情况下,只有用户可以控制循环执行的次数:0或更多。没有任何东西可以让你循环然后做一些事情,如果你根本没有循环或者你认为为...其他
循环应该do。
你可以把一个if放在循环中:
You can't apply anelse
to any kind of loop construct -for
,foreach
,do
, orwhile
- because they aren't conditional statements, although that contain a conditional expression. In the case of a loop, that is only ever user to control how many times the loop will execute: 0 or more. There isn't anything which lets you "loop and then do something if you didn't loop at all" or whatever it is you think afor...else
loop should do.
You can put an if inside the loop:
for (int i = 0; i < 10; i++)
{
if (i % 2 == 0)
Console.WriteLine("Even");
else if (i != 9)
Console.WriteLine("Prime");
else
Console.WriteLine("Odd");
}
并且这样可以正常工作:
And that'll work fine:
Even
Prime
Even
Prime
Even
Prime
Even
Prime
Even
Odd
但是没有什么到 else
关于一个循环!
But there is nothing to else
about a loop!
这篇关于在C#中的if else if和else语句之间循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文