1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators...
-
Upload
damon-palmer -
Category
Documents
-
view
215 -
download
2
Transcript of 1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment 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!
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
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”);
4
Indentation
Visual Studio can indent control structures properly for you.Highlight relevant codePress Ctrl-K, Ctrl-F
// 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