U3: Nested If Statements Flashcards
Program Control
- How program executes code, makes decisions and organizes functions
- How and which lines of code get executed
Sequential Program Control
Lines executed from first to last; top to bottom
Selection and Program Control
Computer makes choices on what to execute based on data.
Switch Statement Code
switch (variable) {
case “any”: case “ANY”:
codea;
break;
default:
codeb;
break;
}
Case Fall-Through
W/out break function, program executes each next case until reaching “break”
Switch Statements
- Similar to if-then-else statement
- Useful when decision based on single character, word or value
Quotations with Cases
Use “” for characters; no quotations for numbers
Indenting and Braces
After every open brace, next line of code must be indented further
Nested if-then-else Statement
If-then-else statement programmed inside another if-then-else statement
White Space
Empty space/lines in the program
Coding Style
How code looks; Each person has a different coding style
Aspects of Coding Style [A]
- How/when comments used
- # of spaces for indentation
- Use of white space
Aspects of Coding Style [B]
- Naming of variables and functions
- Code organization
- Patterns used and avoided
Style Guides
- Set of rules outlining how person’s programming works
- Workplaces and languages can have rules/conventions
Aspects of Style Guides [A]
- Communication is key so everybody can agree
- Makes old code easier to understand