12-control-statements

12-control-statement - Steve Cooper CS 106A Handout#12 Control Statements Based on a handout by Eric Roberts This handout offers some additional

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Steve Cooper Handout #12 CS 106A January 14, 2010 Control Statements Based on a handout by Eric Roberts This handout offers some additional notes on Java’s control statements (described more fully in Chapter 4 of the textbook) that emphasize the important concepts. It also describes a programming problem making use of various control structures. To write programs, you need to understand control statements from two perspectives: you must have a holistic sense of when to use them and why, but you must also learn to understand the reductionistic details. For this big-picture perspective, you can rely to a large extent on your experience from Karel: If you want to test a condition that requires an if statement in Karel, you need the if statement in Java. If you would use the while or for statement in Karel, you will presumably use the same statement form in Java. The other holistic point that is essential about control statements is that the control line is conceptually independent from the body. Thus, if you see a construct like for (int i = 0; i < 10; i++) { Control line statements Body } the statements in the body will be repeated for each of the values of i from 0 to 9. It doesn’t matter at all what those statements are. Boolean data
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/24/2011 for the course CS 106A taught by Professor Sahami,m during the Spring '08 term at Stanford.

Page1 / 3

12-control-statement - Steve Cooper CS 106A Handout#12 Control Statements Based on a handout by Eric Roberts This handout offers some additional

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online