If - Else statements
All right.... This is definitely one of the lessons that i have been looking forward to. In this lesson we are going to learn how to work with the If - Else statement in code.
This statement is fundamental for the creation of code and being able to decipher between different pieces of information and use the information more intelligently.
At the beginning of the statement is the word "If". this word sets up everything that we need to know about what the statement does. It basically asks is something true or not true. It is a classic yes or no question. If the statement is true then we will run a certain set of code. If it is not true then we will run a different set of code.
The different set of code is run off of part of the statement called "else". The "else" is the piece that lets you run the other set of code. essentially saying that the first part of the statement was not true therefore run this area of code instead.
Clear as mud???
Understanding this simplifies everything else that we need to know to run some programs and call upon higher functionality.
Some basic rules to know when working with "If - Else" statements:
1. Whatever is to be tested needs to be a true or false/yes or no question. Otherwise we will get a syntax error
2. Whatever is to be tested must be put into parenthesis - example: if (value == 0)
3. You do not need a ";" at the end of a if statement
4. Whatever commands or statements that you want to run inside the "if" statement need to have a "{" at the beginning and a "}" at the end.
This statement is fundamental for the creation of code and being able to decipher between different pieces of information and use the information more intelligently.
At the beginning of the statement is the word "If". this word sets up everything that we need to know about what the statement does. It basically asks is something true or not true. It is a classic yes or no question. If the statement is true then we will run a certain set of code. If it is not true then we will run a different set of code.
The different set of code is run off of part of the statement called "else". The "else" is the piece that lets you run the other set of code. essentially saying that the first part of the statement was not true therefore run this area of code instead.
Clear as mud???
Understanding this simplifies everything else that we need to know to run some programs and call upon higher functionality.
Some basic rules to know when working with "If - Else" statements:
1. Whatever is to be tested needs to be a true or false/yes or no question. Otherwise we will get a syntax error
2. Whatever is to be tested must be put into parenthesis - example: if (value == 0)
3. You do not need a ";" at the end of a if statement
4. Whatever commands or statements that you want to run inside the "if" statement need to have a "{" at the beginning and a "}" at the end.
Pre-Assignment Videos
The Assignment
We are going to go back to a previous lesson and finish it up as working code. In our Pseudo-Code lesson we worked on turning a scenario into Psuedo-Code for a program. In this lesson we are going to turn that Pseudo-Code into a working program. Please keep in mind that the program that you will build is the one in the assignment about Red and Blue seeds. We are not working on the Pseudo-Code for our friendly little plumber, although that would be fun as well. There is a small video that should help you get your Pseudo-Code properly prepared for this lesson and that is what follows....