# Conditional statements and Loop structure

## If…Then..Statement

The If…Then statement is used to evaluate whether a condition is True or False. You can use If…Then block to execute one or more statements conditionally. Syntax: If <condition> Then [statements] Else [else statements] End If Example: if a>5 Then a=a+10 Here condition is that ‘a’ should be greater than 5 and if it is …

## If…Then..Else Statement

It conditionally executes a group of statements depending upon value of the expression. If…Then…Else block is used to define several blocks of statements ,in order to execute one block. Syntax: If <condition>then [statements] Else if <condition>Then [else if statement] . . . Else [elsestatement] End If Example: If a<10 then a=a+10 elseif a>15 then a=a-10 …

## Select Case Statement

It is just as the alternative of If…Then…Else statement.It executes one statement in several groups of statements. A Select Case provides the same functionality as the If…then…Else statement but it makes the code more efficient and readable A Select Case works with a single test expression. Value of the statements will be dependent on test …

## Do…Loop Structure

Do…loop is used to execute a block of statements for indefinite number of times. There are several variations of Do…Loop statement. Each variation evaluates a numeric condition to determine whether to continue execution or not. Syntax: Do While <condition> statements… Loop Note that: 1.When Visual Basic executes Do While loop, it first tests condition. 2.If …

## For…Next Structure

For…Next loop is used when you know how many times you want to execute loop.But in case of Do While it is not the case. Do While is used when you do not know how many times you want to execute that particular loop/Condition. Syntax: For counter = start To end [Step increment] statements Next …