07b-Statements

07b-Statements - Statement Blocks • A Compound...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Statement Blocks • A Compound statement (or block) is a set of statements enclosed in braces { int x = 5; double y = readDouble("y: "); println("y = " + y); } • Variable’s scope is block in which it is declared • Scope : lifetime of variable • When the variable is available to be used if statement • General form: if ( condition ) { statements } if ((num % 2) == 0) // can omit braces println("num is even"); // if one statement Any boolean condition/variable if ((num % 2) == 0) { println("num is even"); println("Oh, and Beat Cal!"); } • Use braces with if with more than one statement • Good idea to use braces (block) even if there is only one statement in the if if-else statement • General form: if ( condition ) { statements } else { statements } f ((num % 2) == 0) { if ((num % 2) == 0) { println("num is even"); } else { println("num is odd"); println("and so are you"); } Cascading if if (score >= 90) { println("A"); } else if (score >= 80) { println("B"); } else if (score >= 70) { println("C"); } else { println("Bad Times"); } switch...
View Full Document

{[ snackBarMessage ]}

Page1 / 14

07b-Statements - Statement Blocks • A Compound...

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

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