CSE 123C.001 2-25-08

CSE 123C.001 2-25-08 - Loops: while, do/while, and for True...

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

View Full Document Right Arrow Icon
CSE 123C February 25, 2008 Possible make up class on March 27—will let us know for sure Midterm on Friday—everything up to the for statement slide (last slide included on midterm is the data validation loop slide) Switch statement switch (expression) { case constant: statement(s); break; case constant: statement(s); break; /*default*/ default: statement(s); } Break- breaks the flow of control, skips the next statements and goes to the end of the program, otherwise it will give all outputs, don’t need it for the default because you execute everything from the default to the end Expression must evaluate to either a type int or char Switch (code / 10) reserve word case must be followed by a constant switch (rank) { int char
Background image of page 1

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

View Full DocumentRight Arrow Icon
case 1: case 2: cout << “lower division” break; case 3: case 4: cout “upper division” break; case 5: cout “graduate student” break; default cout “invalid rank” endl; } Repetition- executing a statement more than one time (loops)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Loops: while, do/while, and for True condition decides how many times the code is repeated; infinite true never ends and will crash the system Loop continues until the expression is false i=1 sum += (i++); sum=sum + i; i = i + 1 while (i < n) { sum = i + sum; i++; } cout for the above statement, if n=5 sum =1, i=2 sum=3, i=3 sum=6, i=4 sum-10, i=5 all variables must be initialized tracing-going through the loop sentinel loop: midterm next Friday (return) becomes MIDTERM NEXT FRIDAY (return) (return is not part of the code in this example) Each letter has a numerical value If ‘a’=36 and ‘m’=100; take the difference and add it to the value of ‘A’ to get ‘M’ Do/while loop Code always done at least once Code done first (not checking expression) Examples on slides, study slides for midterm!...
View Full Document

This note was uploaded on 04/08/2008 for the course CSE 123c taught by Professor Elkarboutly during the Spring '08 term at UConn.

Page1 / 3

CSE 123C.001 2-25-08 - Loops: while, do/while, and for True...

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

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