Date post: | 03-Jan-2016 |
Category: |
Documents |
Upload: | buddy-williams |
View: | 217 times |
Download: | 0 times |
The C# language fundamentals
( II )
Po Feng, Tsai
Switch statements
An alternative to nested ifs Similar to Matlab
The goto and break keywords The switch statement
Fall through Goto
Move to another address with specified label Create a label and the goto the label
Break Jump out of the switch statement
Averting from using goto is strongly suggested Complicating your codes
Fall through you cannot fall through to the next ca
se if the case statement is not empty
Loops The while loop
Example
Exercise 7 Please try to use the while loop to pri
nt the following message * ** *** **** *****
Debugger
Loops The do…while loop
Example
Loops The for loop
Example
remainder
Exercise 8
Please try to use the for loop to print the following message * ** *** **** *****
Continue & Break
The continue statement causes the loop to return to the top and continue executing
The break statement causes the loop to stop and jump out of executing block
Example
Alarm system (3-15)
Exercise 9
Please implement a multiplication table (3x9) with any of the loops mentioned above
The ternary operatorUsage
Example
Preprocessor Directives
Before your code is compiled, another program called the preprocessor runs and prepares your program for the compiler begin with the pound sign (#) Usually for debugging purpose
Example 1
Example 2
#region
Used to mark off areas of code and collapse them Paired with #endregion Additional information can be attached ri
ght after the label
Click here
Click here