Making Decisions in Code

One of the most important statements in a program is the If statement. With the logic that If provides, your application can begin to analyze data and make decisions based on the analysis. For example, your program can display a three-button message box and determine, with the If statement, which command button the user should click to close the message box.

If uses the comparison operators you learned in the previous chapters, such as < and >=. If performs one of two possible code actions, depending on the result of the comparison. In other words, If uses a comparison operator result to test data and might execute one or more lines of subsequent code, depending on the result.

Before If, code was executed sequentially, ...

Get Absolute Beginner's Guide to Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.