Warning: The magic method Slickr_Flickr_Plugin::__wakeup() must have public visibility in /home/kenbauer/public_kenscourses/tc101fall2015/wp-content/plugins/slickr-flickr/classes/class-plugin.php on line 152
‘#Mastery16’ Articles at TC101 Fall 2015, Page 5
Introduction to Programming Python and C++

Tag Archives: #Mastery16

MASTERIES 15 & 16: Using the conditionals “If” and “else”

     (The credit of the background image goes to https://flic.kr/p/hr55F2 and https://flic.kr/p/oSm9nY) This is Mastery #13 and it’s all about the conditionals “if” and “else”. These ones are the most common conditional statements, which are the ones that determine if an action should be followed o not, depending on one condition. It is very easy to use and […]

Mastery 15 and 16: Use of the conditional “if” and use of “else” with a conditional

This time I master the use of if as a conditional and else as well with a conditional (else if), here are the steps I follow: Create a program like the one of temperature change from F to C. Use if as the first conditional, c>=100. Use else if as the second conditional, c<=100. And… More Mastery 15 and 16: Use of the conditional “if” and use of “else” with a conditional

If and Else #Mastery15 #Mastery16

Hi! This Masteries are related to conditional statements, which are used to determine whether an action should be done or not. For instance in if case structure a certain condition should be meet in order to trigger a sequence of steps, the structure is:

if ( Condition ) {

Instructions

}

The condition might be a comparison done with several symbols as  ==, =, != which return a boolean value that determines if the condition is true. Also several conditions might be tested by joining them with the AND (&&) and OR (||)  which returns true if both conditions are met or at least one, respectively. Another value that could be in the condition might be a boolean or true or false which would help to test certain parts of the code or simply supress them. 

In programming the if statement has important implications, for instance it might trigger a command with the touch of a button to move a part of a robot or stop it if a switch is pressed. Also it’s useful to test certain parts of the code without having to erase other segments.

Note: always remember to place a } at the end of the sets of instructions so the program doesn’t report an error or the program ommiting an important part of the code because the condition wasn’t met.

Also, its important to introduce the else statements, which are a series of intructions that are done if the if condition is not met. They always go after the if structure and they should be written as:

else {

Instructions 

}

Here’s a picture of what would be triggered and what wouldn’t:

An application might be a program which turns a led if a button is pressed, if the button is not pressed then the instruction should be to turn it off. An interesting thought would be what would happen if you turn it on and stop pressing the button, without including the else statement?

They are also useful to test several conditions by vinculating with other if statements, that gives different results with different conditions. 

If one intends to return a result with a specific condition, for instance the day of the week if a number from 1 to 7 is given, a solution might be to use several else if statement to fullfil the task. But there are other more efficient ways to solve this and will be introduced in the following masteries. Thanks for reading!

 

The basics of programing: if, elif, else Masteries 15, 16, 17

s There is the code I made to put at work the conditionals. The program basicaly tells you if the number you typed is a float, an integer, a negative integer, or a negative float. So first you ask for… Continue Reading →

What should you work on?

Week #12 and more partial exams for you.

For this week's readings:
C++ (TC1017) should either be looking at support for your project, ImageMagick C++ libraries are a good start.
Python (TC1014) should be finishing chapter 11 (Dictionaries).