6.087 Lecture 4 – January 14, 2010 - MIT OpenCourseWare
[Pages:31]6.087 Lecture 4 ? January 14, 2010
Review Control flow I/O
Standard I/O String I/O File I/O
1
Blocks
? Blocks combine multiple statements into a single unit. ? Can be used when a single statement is expected. ? Creates a local scope (variables declared inside are local
to the block).
? Blocks can be nested.
{ int x=0; { i n t y =0; / both x and y v i s i b l e /
}
/ only x visible /
}
1
Conditional blocks
if ... else..else if is used for conditional branching of execution
i f ( cond ) {
/ code executed i f cond i s true / } else {
/ code executed i f cond i s f a l s e / }
2
Conditional blocks
switch..case is used to test multiple conditions (more efficient than if else ladders).
switch ( opt ) {
case 'A' : / execute i f opt == 'A ' / break ;
case 'B' :
case 'C' :
/ execute i f opt == 'B ' | | opt == 'C ' / default : }
3
Iterative blocks
? while loop tests condition before execution of the block. ? do..while loop tests condition after execution of the block. ? for loop provides initialization, testing and iteration together.
4
6.087 Lecture 4 ? January 14, 2010
Review Control flow I/O
Standard I/O String I/O File I/O
5
goto
? goto allows you to jump unconditionally to arbitrary part of your code (within the same function).
? the location is identified using a label. ? a label is a named location in the code. It has the same
form as a variable followed by a ':'
start : {
i f ( cond ) goto outside ;
/ some code / goto s t a r t ; } outside : / outside block /
5
Spaghetti code
Dijkstra. Go To Statement Considered Harmful. Communications of the ACM 11(3),1968
? Excess use of goto creates sphagetti code. ? Using goto makes code harder to read and debug. ? Any code that uses goto can be written without using one.
6
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- format string vulnerability printf user input
- 6 087 lecture 4 january 14 2010 mit opencourseware
- output printf
- description syntax stata
- write output using printf use backslash to include special
- secrets of printf don colton
- cis 190 c c programming university of pennsylvania
- c function copyright © tutorialspoint
- e format specifier tricks university of virginia
- the c printf fact sheet bytellect
Related searches
- dod 7000.14 r vol 4 chp 6
- dod 7000.14 r volume 4 chapter 6
- dod 7000 14 r volume 4 chapter 6
- dod 7000 14 r vol 4 chp 6
- minecraft 1 14 4 server download
- 2010 ford 4 6 engine problems
- x2 x 6 x2 4x 4 0
- 14 5 6 5 grendel barrel
- 2010 4 6 ford engine problems
- 2010 ford 4 6 3v problems
- 2010 ford 4 6 firing order
- 2010 ford 6 4 diesel problems