Conditional logic is the process of making decisions based on user input. This is a vital part of programming to understand. In fact, some may even argue that Conditional logic is all that programming is. Conditional logic always has some Boolean expression that can come to two possible conclusions: True or False. Your code then executes based on the value of this Boolean expression.
Before we discuss conditional logic at it's full potential, you must first understand the operators to use. Here are some of the operators in Visual Basic:
NOTE: You can use these operators for both numbers AND strings. Numbers reference the values (greater than, less than), while strings go by alphabetical order, with A being the least and Z being the most.
Once you understand these, we can learn about the greatest Conditional logic there is. The "If" statement is probably the most used statement in coding to date. It has a simple structure, yet is capable of the most complex conditional logic. For example:
NOTE: In Visual Basic, only one condition will run in an if statement. By this, I mean that even if UserEntry is 17 in the example, the second condition will never run because 17 is greater than 10. It is vital to keep this in mind when using Visual Basic.
When using an If statement, it is not required to have any ElseIf or Else statements. In Visual Basic, the only requirements are the "If," the condition, the "Then," and the "End If."
Next we will learn about another type of Conditional logic: The "Select Case" Statement.
Previous Next