1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators...

5
1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators Escape characters More on type casting/conversion in examples coming up AND READ Fig 6.19 and Section 5.11!

Transcript of 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators...

Page 1: 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.

1

Chap 4. Data

Should knowDeclare & Initialize variablesDeclare constantsAssignment OperatorsIncrement and Decrement OperatorsPrecedence of OperatorsEscape charactersMore on type casting/conversion in examples coming up AND READ Fig 6.19 and Section 5.11!

Page 2: 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.

2

Chap 5-6. Control Structures

Program of controlSequential executionSelection structure

• The if and if/else statements• Switch statement• The goto statement

Repetition structures• The while and do/while loops (chapter 5)• The for and foreach loops (chapter 6, 8)

Powerpoint slides modified from Deitel & Deitel

Page 3: 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.

3

Conditional Operator (?:)

Conditional Operator (?:)C#’s only ternary operatorSimilar to an if/else structureThe syntax is:

(boolean value ? if true : if false)

Example:

Console.WriteLine (grade >= 60 ? “Passed” : “Failed”);

Page 4: 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.

4

Indentation

Visual Studio can indent control structures properly for you.Highlight relevant codePress Ctrl-K, Ctrl-F

Page 5: 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.

// do-while repetition

// initialization of loop countercounter= 1;

// do 10 times

do

{// output counterConsole.Write (counter);++counter;

} while ( counter <= 10 ) ;

Console.WriteLine ( );

Blank line

Program Output

1 2 3 4 5 6 7 8 9 10