Conditional statements and loops

Conditional statements and loops - Conditional statements...

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

View Full Document Right Arrow Icon
Conditional statements and loops Introduction Every procedural programming language has conditional statements (if-statements) and iterative statements (loops). You should be familiar with the concepts —unless your only previous programming language was a purely functional language. Therefore, our purpose here is to summarize the Java versions of these statements and point you to the places in the text and the CD ProgramLive for longer discussions of these statements. 1. The block . 2. if-statement . 3. if-else statement . 4. while-loop . 5. for-loop . The block (Gries/Gries, p. 69. ProgramLive, p. 1-4) The block has the form { <sequence of statements and local-variable declarations> } Its purpose is to aggregate (collect together) the sequence of statements and declarations into a single statement. It used below in writing conditional and iterative statements. if-statement (Gries/Gries, p. 69. ProgramLive, p. 1-4) The if-statement has the form if ( <condition> ) <statement> The <condition> is a boolean expression. We generally make the <statement> be a block. The following example shows the conventions used in this course for indenting and the
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 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Page1 / 4

Conditional statements and loops - Conditional statements...

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