BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
June 10, 2015ICS102: while & do-while1 while and do-while Statements.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Loops – While, Do, For Repetition Statements Introduction to Arrays
The If/Else Statement, Boolean Flags, and Menus Page 180
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Introduction to Python
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Invitation to Computer Science, Java Version, Second Edition.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 2 - Algorithms and Design
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
BIT 115: Introduction To Programming Instructor: Mike Panitz
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Repetition. Control of Flow SEQUENCE SELECTION (if..else, switch…case) REPETITION.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
COMP Loop Statements Yi Hong May 21, 2015.
Algorithms and Pseudocode
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Repetition Structures The long awaited …. Repetition Structures I repeat …
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Discussion 4 eecs 183 Hannah Westra.
Whatcha doin'? Aims: To start using Python. To understand loops.
Introduction to Python
Introduction To Repetition The for loop
CS161 Introduction to Computer Science
IF statements.
Programming – Touch Sensors
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Conditions and Ifs BIS1523 – Lecture 8.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Outline Altering flow of control Boolean expressions
Introduction to Object-Oriented Programming with Java--Wu
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Coding Concepts (Basics)
Module 4 Loops.
Let’s all Repeat Together
Building Java Programs
How to allow the program to know when to stop a loop.
Presentation transcript:

BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)

BIT 115: Introduction To Programming 2 Must partner in class! If your partner is absent, partner with someone else –Groups of 2 to 3 students OK –Sit next to each other! You must take on new partners! –3 person groups may have to become two 2-person groups if they get a new member 2

BIT 115: Introduction To Programming Reading for today: –F.2 - Repeating Statements – while loops – Nesting if/while –F.4 - Temporary Memory (counting loops) –F.5 – Parameters Reading for next class (updated syllabus): –2.2.3 – Instance variables, constructors –6.6 & F.6 - Getting user input, printing output

BIT 115: Introduction To Programming 4 A1 being corrected –Might use the Java Code Critic, check Parts 3&4 were biggest problem –difference between showing errors and tracing –only needed to fix compile-time errors –stop tracing when a crash occurs HOMEWORKHOMEWORK

BIT 115: Introduction To Programming 5 Due next Wed 4/23 –Assignment 2 Should be available this evening –Journal #2 Midterm will probably be Mon 4/28 –Plan to post study notes on the website soon HOMEWORKHOMEWORK

BIT 115: Introduction To Programming 6 while loops Important new syntax: while( ) { // multiple statements here. } You could omit the braces & use just one statement, but don’t. Avoid confusion! 6

BIT 115: Introduction To Programming 7 ICE_05_Demo_1 Review 2nd while loop Run it 7

BIT 115: Introduction To Programming 8 Watch for Infinite Loops! while ( someBooleanExpression() ) { // multiple statements here. } Note that if you don’t do anything to change how the expression evaluates, it’ll always evaluates to the same thing. If the expression always evaluates to true, then you’ll be stuck in an infinite loop!

BIT 115: Introduction To Programming 9 Important points The whole loop can be placed anywhere that a normal command can be placed –i.e., anywhere you could write karel.move(); This includes main (as in ICE_05_Demo_1) 9

BIT 115: Introduction To Programming 10 What can I use for ? ICE_05_Demo_1.java code uses a predicate service –This type of service says that something IS or IS NOT true canPickThing() says either true, the robot is beside a thing (in the same intersection as the thing), or false, the robot is not beside a Thing. predicate \Pred"i*cate\, v. i. To affirm something of another thing; to make an affirmation. --Sir M. Hale. 10

BIT 115: Introduction To Programming 11 ICE 05 ICE Part 1: Trace the code, find errors –USE AN EXTRA COLUMN to show the loop condition ICE Part 2: Write code from a flowchart TELL ME when you are ready for lecture for ICE Part 3! 11

BIT 115: Introduction To Programming 12 Variables, comparing quantities So far, we've only created things which have had on-screen representations –Robot, Thing, Wall, etc. However, we need the program to be able to remember stuff –If we want to compare quantities, we'll have to store numbers –We'll start with just whole numbers: integers 12

BIT 115: Introduction To Programming 13 Variables, comparing quantities 1st, you have to ask Java to get you some memory, and you have to give the memory a name. –If it doesn't have a name, how can you talk about it later? int myNewVariable; Once you've created it, you can put a value into it using the assignment operator =. myNewVariable = 4; 13

BIT 115: Introduction To Programming 14 Variables, comparing quantities When you assign something to the variable, it 'sticks', until you assign something else. int myNewVariable; // create & name it. myNewVariable = 4; // myNewVariable has the value 4 myNewVariable = 10; // myNewVariable has the value 10 myNewVariable = -2; // myNewVariable has the value -2 You can also increase the value stored in the variable numMoves = numMoves + 1; ++numMoves; 14

BIT 115: Introduction To Programming 15 Variables, comparing quantities You need to be able to compare quantities too –Operators you can use: OperatorIs true when: A < B A is less than B A <= B A is less than or equal to B A > B A is greater than B A >= B A is greater than or equal to B A = = B A is equal to B –Notice that this is composed of two equal signs (=) right next to each other A != B A is not equal to B 15

BIT 115: Introduction To Programming 16 Variables, comparing quantities Pulling this all together, we get something like: int numMoves = 0; while (numMoves < 4) { this.move(); numMoves = numMoves + 1; } You should trace this with an extra column for the numMoves values 16

BIT 115: Introduction To Programming 17 Loop Patterns There are certain patterns of code that you'll see again & again –For example, if you want to count from one number to another, you'll end up with code that's similar to every other time you want to do this –These similarities are good to notice Instead or reinventing the wheel each time, REUSE patterns –The details (like what a variable is named, etc.) will change –The important parts, the structure, won't change 17

BIT 115: Introduction To Programming 18 Counting patterns Counting up: page 259 Counting down: page 204 All textbook patterns: page 826 MAKE SURE TO ACTUALLY COUNT UP or DOWN!!!! –If you don't actually increase the value of count- variable by 1, the computer won't do it howManyTimes = howManyTimes + 1; // same as ++howManyTimes; or howManyTimes++; 18

BIT 115: Introduction To Programming 19 ICE Parts 3, 5-6 SKIP Part 4 until Parts 5-6 are done 19