Download presentation
Presentation is loading. Please wait.
1
A basic tutorial for fundamental concepts
Intro to Programming A basic tutorial for fundamental concepts
2
Programming as Logic How programming is relatable to everyday logic
3
Math! Most of programming is applying simple math to difficult problems. You don't even necessarily need higher-level math like calculus. Think about making a pyramid from 1 to 100 steps: all you have to do is count to 100, and make a column that's x high for each number you count. When you get to 100, do it again, just counting down. 100... 2... 2 1
4
Variables & Functions Programming boils down to two important concepts: variables and functions. Exactly as in math, functions are structures that take in some value and return another. For example: f(x) = 2x Variables are what you pass to functions as arguments. 'x' is an argument, and you might give a function more than one: If you want to remember the output of a function, you might instantiate, or create, a new variable: f(x, z) = x*z The function would return one number, and x and z won't change. y = f(x, z)
5
Not Just Numbers Of course, not everything in programming is a number. What about letters? Words? 'Yes' and 'no'? They all have special names, because they're all types of information, and ways to use them: Whenever you declare a variable, you need to specify its type: Name Type Examples Integer (number) int, long 1, 0, 100, -100, Floating point (number) float, double 1.0, 0.0, -1.0, Character (letter) char, chr a, B, $, %, }, '0', '1', … String (word, sentence) String, string, str "Hello", "Goodbye", … Boolean (yes or no) boolean, bool true, false double y = f(x, z)
6
Comparing Things When you want to relate one variable to another, you would use a comparison. We use many types of comparisons in everyday language, and programming translates them into symbols. The result is a boolean true or false. Comparison Example Less than x < y Greater than x > y Less than (or equal to) x <= y Greater than (or equal to) x >= y Equal to x == y Not equal to x != y
7
Checking Conditions Say you only want to perform a task if a certain comparison is true or false – a condition. You would use what's called an if-then-else block, which runs certain code based on one or many conditions: if (x == y) { // run code for when x is equal to y } else { // run code for when x is not equal to y }
8
Object-Oriented Programming (OOP)
A well-defined structure for how programming languages work
9
The Real World in Code Think about the room around you. There are pieces of furniture, light fixtures, paintings, tile, carpet or rugs, a door, probably a window or two – none of which are numbers, letters, words, or booleans. So how do you make one in code? Anything that isn't a fundamental type, like numbers and booleans, can be defined as a object with many fields (or properties) that are themselves fundamental types: dimensions, mass, color, material... wood 2x2 ft 4 legs
10
Everything is an Object
With this idea in mind, let's make everything an object. We can even wrap fundamental types into objects, like Integer, Double, and Character, with a fundamental type called 'value' or 'state' to keep track of the actual number. Then, we can use fundamental types as if they're objects. We'll see why this is important later. 1 0.3 Object: Integer Object: Double Object: Chair
11
Family Trees What if we want to separate chairs into wooden and metal chairs to give them different properties? We might give a wooden chair a property for what type of wood it is, and a similar property for a metal chair for what type of metal it is. Chair We can do this by extending the Chair class – making a child, with Chair as the parent, so that each has the same properties of a Chair, with their own special properties too. WoodenChair MetalChair
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.