Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

Chapter 3. If, Else, and Switch

In the previous chapter, we discussed the importance of memory and how it can be used to store data inside a computer. We spoke about how memory is reserved for your program using variables, and how we can include different types of information in our variables.

In this chapter, we will talk about how to control the flow of our program and how we can change what code gets executed by branching the code using control flow statements. Here, we'll discuss the different types of control flow, as follows:

  • If statements

  • How to check whether things are equal using the == operator

  • Else statements

  • How to test for inequalities (that is, how to check whether one number is greater or smaller than another using the operators >, >=, <, <=, and !=)

  • Using logical operators (such as not (!), and (&&), or (||))

  • Our first example project with Unreal Engine

  • Branching in more than two ways:

    • The else if statement

    • The switch statement