New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Dorris Borer
Dorris Borer
GPA 3.84


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course

Popular in Electrical Engineering

This 5 page Class Notes was uploaded by Dorris Borer on Monday September 28, 2015. The Class Notes belongs to ESE112 at University of Pennsylvania taught by Staff in Fall. Since its upload, it has received 5 views. For similar materials see /class/215450/ese112-university-of-pennsylvania in Electrical Engineering at University of Pennsylvania.

Similar to ESE112 at Penn

Popular in Electrical Engineering


Reviews for INTROTOESE


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/28/15
Introduction to Programming WI39fz Java for Beginners Control Structures Sequential Control Flow I Consists ofjust a list of commands to be done in order Welcome to Dr Java gt int num 2 gt int sqNum gt sqNum num num gt SystemoutprintlnsqNum Orjust type1sqNum 2 EsE112 1I17 What are control Structures I Limitations of sequential control ow I Cannot choose whether or not to perform a commandinstruction I Cannot perform the same command more than once I Such programs are extremely limited I Control structures allow a program to base its behavior on certain conditions EsE112 2I17 Recap Boolean Boolean is one of the eight primitive types I Only 2 value true orfalse I Booleans are used to make yes or no decisions I All control structures use Booleans The following expression each give a Boolean result 25 gt 24 ampamp 12 13 resuts to false 25 gt 24 12 13 resuts to true I Thus based on certain conditions we can alter the outcome or flow of the program EsE112 3M7 Conditionals if statements if statement if condition statement 5 If the condition is true then the statements ie instructions Will be executed Othenvise itthey won t An if statement is a flow control statement It is also called a conditional or a branch We ll see several flavors An if all by itself An if with an else part An if with an else it part Assume X is an integer ifX 2 0 Systemoutprintlnx is even EsE112 m7 EsE112 5M7 Example ifelsequot statement ifelsequot statement Example Syntax amp if condition Explanation statement 5 Determine smaller of two integers if condition numbers amp put it variable min statement5 else t statements n mm 5155 int X statementss int y 10 A 39 39 t H ssume X ls an in agar Ifthe condition is true ifX 2 0 if x lt y then the statements Systemoutprintlnx is evenquot min x in the i c are execu Else Else 0th 39 39fth 39 Systemoutprintlnx is oddquot min 3quot anxxeTAgil era s statements in it are 55112 El 7 ESE112 ex ed if with elseif statement if condition I No limit on else ifquot statement 5 statements I The else condition is 59 if condition usually a default statements condition I For completeness else EsE112 8M7 Cascading ifelse char userChoice Ask user for input and store it in userChoice if userChoice q Systemoutprintln quitting else if userChoice a Systemoutprintln adding else if userChoice 5 Systemoutprintln saving else Sys tem out println unrecogni zed choice Note You can avoid the curly brace after condition if only one statement is to be performed EsE112 9M7 Nested ifstatements An if within an if Truth Table if condition1 if condition2 What Values must the statement 5 A conditions have in order for block A to run B C else statements B A B C condition1 T else statementss C cond39t39on2 EsE112 1on7 The infamous dangling elsequot if x gt y When is statementB if y lt Z executed statementA else In other words which stat ntB if is the else paired with An else is paired with the last if X gt Y elseless if regardless of spacing if Y lt 2quot unless dictate otherwise statementquot else statementB 555112 m A Loop I A simple but powerful mechanism for making lots of things happen I Performs a statement or block over amp over I Usually set upto repeat an action until some condition is atisfied I Computing Scenarios Examples I Run an application until user hits quit button I Read characters until end of file reached I Deal card hands until game over EsE112 12I17 Syntax of the whie statement While condition statement s l I condition is a truefalse boolean expression I If condition is initially false the statement is never executed I If condition is true statanent is executed and condition is reevaluated I The statement should eventually make the loop stop EsE112 13m A whie Loop to Print Numbers Print the numbers 1 thru 10 int x 1 while x lt 10 Systemoutprintlnx x x 1 l I What happens if you forget the statement x x 1 I We print value 1 forever I Known as in nite loop EsE112 14m More InfHire Loops Some infinte loops are intentional while true statement 5 Others are not int x 5 while x lt 10 statement 5 which don t change x EsE112 15m Compute Square of first 10 numbers In Squarejava int num 1 int sqNum 0 while num lt 10 sqNum num num Systemoutprintlnnum quot quot sqNum num num 1 ESE112 16I17 For Loop for init endtest reinit statement I Executes loop body as long as endtest evaluates to TRUE I Initialization and reinitialization code included in loop statement I Note Test is evaluated before executing loop body EsE112 17I17 While vs For39 Explanation int x 1 An example of while x lt 10 a while loop Systemoutprintlnx that has this patte n x x 1 for int x 1 x lt 10 x x 1 A for loop Systemoutprintlnx that 51055 the same thing Note For loops are used generally for bounded iteration EsE112 18I17 Summary of Loops Type of Loop Syntax while while condition statement5 for for exprl condition expr3 statement5 EsE112 19m


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.