Objective

Students should be able to get started on programming their robots and start to become more comfortable with the VEX Code interface. They should also be able to understand the different variables, conditions, and code formats.

Attention

Although you now have a built robot, the code you are using was written by someone else. The goal of today’s lesson is to get you comfortable enough with VEXcode Pro to be able to write your own code to better suit your needs.

Learners Guidance

Variables and Data Types

When defining variables in code, it is important to keep track of what kind of variable it is. The different types of variables are listed below:

// integer values are called int
int number1 = 14;

// floats are decimals of higher accuracy
float number2 = 14.1234;

// doubles have twice the accuracy of floats
double number3 = 14.123456789;

// booleans are true or false values, useful for conditionals!
bool perhaps = true;

Conditional Statements and Loops

Sometimes we want an action to occur only when a certain condition is met. This is when we use condition statements such as IF, ELSE IF, and ELSE.

Condition statements use conditions to make decisions. A condition results in true or false. A condition can compare and or hold values but it should result in a true or false. For example, a condition can be user controlled inputs, such as buttons getting pressed, a certain amount of time passing, or motors reaching a certain target.

IF Conditional Statement Syntax

if( condition ){
		//code that will run if condititon is met
}

Example

bool condition = true; //condition variable is set to TRUE

if (condition == true) {.   //checking if CONDITION variable hold the value "true"
	// code block A
}