Conditional statements

Conditional statements are used to verify the conditions in the programming. On the basis of conditional statement, we can take actions like reporting the failure, moving to next step, stopping the execution etc.

We have following types of conditional statements.

1. If…Then
2. If…elseif..Then
3. else..
4. Nested If..else
5. Select statements

IF…Then: We can check the condition,on the basis of False or pass output of condition we can perform required statements. It should be enclosed with IF and End If statements.

Syntax:
If (condition)..Then
     {Statement or a block of statement}
End if

If …Elseif..Then: We use ‘elseif’  when we want to verify multiple condition.

Syntax:
If (condition)..Then
     {Statement or a block of statement}
elseif (condition)..Then
     {Statement or a block of statement}
End if
We can put any no. of elseif into the code.


If..Else: If the condition in ‘If  Then’ is not true, then control will go to the else part.

Syntax:
If (condition)..Then
     {Statement or a block of statement}
else
      {Statement or a block of statement}
End if

Nested If: means that one If condition into another If condition.


Select Case Conditional statement: Suppose, we need to verify multiple conditions and we use ‘If..elseif’. Then, we have to put multiple elseif conditions. It is not a good practice to put so many elseif conditions. As a solution, we have another conditional statement called ‘Select case’ statements. It should be enclosed with ‘Select Case’ and ‘End Select’ statements.

Syntax:
Switch Case variable
Case VariableValue
{Statement or a block of statement}
Case VariableValue
{Statement or a block of statement}
Case else
{Statement or a block of statement}
 

Print Friendly, PDF & Email
Working with Excel
Encrypt and Decrypt the password in UFT
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *