Saturday, May 7, 2011

VB.net Tutorial 3.1 : Control stuctures

Control stuctures :


If : usefull to make condition in your code


example : if nb<5 then command()

OR

if nb<5 then
command()
end if


OR

if nb<5 then
command1()
else
command2()
end if


Select Case

An example is better than lot of text so :
example :
select case nb
case is <=10
Msgbox("the number is < 10")
case 11 to 19
Msgbox("the number is betwen 11 and 19")
case else
command1()
end select

IIF : evaluates a condition and returns different values regarding the result of the condition


example : IIF(condition, value_if_true,value_if false)


While : repeat instruction until the condition is false

example : while condition
...
end while

Do Loop : can be used with the keywords while or until

example : do
...
loop while condition

OR

do
...
loop until condition

For : The for structure is used to execute a bloc a number of time with a counter.

example : dim i as integer
for i = 1 to 10 step 2
msgbox(i)
next


For each : Very usefull to access evry element in an array.

example : For each element in foobar 'foobar is the array to access
...
next





No comments:

Post a Comment