basic building blocks of programming. variables and assignment think of a variable as an empty...
Post on 21-Dec-2015
216 views
TRANSCRIPT
![Page 1: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/1.jpg)
Basic Building Blocks of Programming
![Page 2: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/2.jpg)
Variables and Assignment• Think of a variable as an empty container• Assignment symbol (=) means putting a value
into a variable (container)– This is not the same as ‘equal’
• Initialization– Before doing repetitive computations, usually needs
initialization value (usually 0 or 1)
• Swapping– To swap values between two variables, we need a
third dummy variable to temporarily store the value.
![Page 3: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/3.jpg)
• Sequential execution
• Branching
• Loops
• Nested structure
![Page 4: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/4.jpg)
![Page 5: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/5.jpg)
Sequential execution
• Proper sequence is important.
• Following instructions in different sequences will give different results (or no result)
![Page 6: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/6.jpg)
![Page 7: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/7.jpg)
Branching
• Also called– Conditional structure– Decision– IF statement
![Page 8: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/8.jpg)
Loops
• Also called repetition, recursion
• Two types– Counted– Conditional
• Avoid infinite loops!
![Page 9: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/9.jpg)
Patterns and Structure
• Separate data and variables– Look at empty variables
• Look for patterns and structure of empty variables to help in constructing algorithms– Loops (repetitions)– Conditions (branching)
![Page 10: Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into](https://reader036.vdocument.in/reader036/viewer/2022062516/56649d635503460f94a45bc0/html5/thumbnails/10.jpg)
Walk-through
• Also called tracing an algorithm
• To check whether the algorithm would produce the expected result