Computer Science 1026A/B Lecture Notes - Lecture 3: Substring, Boolean Data Type, Floating Point
terubarenuka and 39895 others unlocked
26
COMPSCI 1026A/B Full Course Notes
Verified Note
26 documents
Document Summary
The (cid:858)if(cid:859) state(cid:373)e(cid:374)t: allows a program to carry out different actions depending on the nature of the data being processed, two key words if and else. Compound statement span multiple lines & consists of a header and a statement block ( if" statement is a simple example: header. : includes a comparison statement and requires a colon : at the end: statement block. : a group of one or more statements. : signal that one or more statements are part of a given compound statement. : executed only if header is true, if header is false, the entire block is skipped: block structured code. :code to calculate discount received after spending more than 100: common errors. : if the same code is duplicated in each branch, move it out of the if statement. :can be used anywhere that a value is expected. :complexity is bad . this shortcut is difficult to read and a poor programming practice!