If Conditions/Statement Difference

Posted by Bugwee under VB.NET on 5/26/2011 | Points: 10 | Views : 2382 | Status : [Member] | Replies : 3
Hello Everybody,

What is the difference between this IF statements below. Which is better to use? or On what scenario could the the first if statement and the 2nd if statement can be use or applicable?

If txtName.Text = "simple" Then txtResult.Text = "simple"

and

If txtName.Text = "not simple" Then
txtResult.Text = "not simple"
End If


Regards,
Bugwee




Responses

Posted by: Ndebata on: 5/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hey all it depends on the requirement( i.e what you need to check for the Control flow)
Lets say you want to do Something when value of a variable is > 0.
Hence your should check condition for > 0.
if(x>0)
{
//Do something.
}
Otherway you need to check the negation of it if you want to go with only if clause without else clause.
if(!x<=0)
{
//Do something.
}
Thanks,
Debata

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 5/27/2011 [Member] Starter | Points: 25

Up
0
Down
different languages has different syntax
in c#
if(condition)
statement...
no need to give then end if

in vb
if condition then
statement
end if


Thanks&Regards
LakshmiNarayana Nalluri.

Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bugwee on: 5/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hello guys,

The category that i have selected is VB.NET

@Ndebata: Thanks. I have understand what you mean.
@Lakn2: There's an if condition in VB that is not necessary to put an "end if" and there is also an if condition that will end with "end if".
Look at the code i have posted above. The first if condition don't have an end if but on the second condition ended with end if.

What is the difference between the two conditions?

Thanks and Regards,
Bugwee



Bugwee, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response