Académique Documents
Professionnel Documents
Culture Documents
NET
The parameters of VB.Net methods (sub procedures and functions) can be marked as 'Optional'. The optional parameters must be the final parameter of a method. A method with an Optional parameter may be called either with the optional parameter or without the optional parameter. An Optional parameter is that they must be specified with the default value.
If Else
If (Condition) Then Statements executed if condition is true Else Statements executed if condition is false EndIf
We can also have Else If block in If Else statements Every If statement must contain a then and an end if
Is keyword: specifies a range of values when you know only one value, either the minimum or the maximum Case Is > 10
counter is a numeric variable that keeps track of how many times the loop instructions are repeated startvalue, endvalue, and stepvalue
Must be numeric Can be positive or negative, integer or noninteger Default stepvalue is 1
Do While Loop
Do While(a<>0) Console.Writeline(a) a=a1 Loop Do Console.Writeline(a) a=a1 Loop While(a<>0)
Do Until Loop
Do Until(a=0) Console.Writeline(a) a=a1 Loop Do Console.Writeline(a) a=a1 Loop Until(a=0)
Comparison Operators
= > >= < <= Is equal to Is Greater Than Is Greater Than or Equal to Is Less Than Is Less Than or Equal to
<>
Is Not Equal to
Comparison Operators
Comparison operators are also referred to as relational operators All expressions containing a relational operator will result in either a true or false answer only Comparison operators are evaluated from left to right, and are evaluated after any mathematical operators
7>3*4/2
Logical Operators
Not Reverses the truth value of condition; false becomes true and true becomes false. 1
And
AndAlso Or
All conditions connected by the And operator must be true for the compound condition to be true.
All conditions connected by the AndAlso operator must be true for the compound condition to be true. Only one of the conditions connected by the Or operator needs to be true for the compound condition to be true. Only one of the conditions connected by the OrElse operator needs to be true for the compound condition to be true. One of the conditions connected by Xor must be true for the compound condition to be true.
2
2 3
OrElse
Xor
Short-circuiting evaluations
VB.NET features two logical operators that help make programming more logical. These new operators [AndAlso and OrElse] add a lot to the old And and Or operators. They offer advantages in two general categories: We can avoid executing part of a logical expression to avoid problems. We can optimize code by not executing any more of a compound expression than required. AndAlso and OrElse are pretty much like And and Or except that they will "short circuit" an expression once the outcome is guaranteed.
Logical Operators
False
True
Logical Operators
True
False
False
True
False
False
False
False
False
Logical Operators
True
False
False
(not evaluated)
False
False
Logical Operators
False
False
False
Logical Operators
If condition1 is
True False
And condition2 is
(not evaluated) True
Value of Result is
True True
False
False
False
Logical Operators