19
The C# language fundamentals ( II ) Po Feng, Tsai

The C# language fundamentals ( II ) Po Feng, Tsai

Embed Size (px)

Citation preview

Page 1: The C# language fundamentals ( II ) Po Feng, Tsai

The C# language fundamentals

( II )

Po Feng, Tsai

Page 2: The C# language fundamentals ( II ) Po Feng, Tsai

Switch statements

An alternative to nested ifs Similar to Matlab

Page 3: The C# language fundamentals ( II ) Po Feng, Tsai
Page 4: The C# language fundamentals ( II ) Po Feng, Tsai

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

Page 5: The C# language fundamentals ( II ) Po Feng, Tsai

Fall through you cannot fall through to the next ca

se if the case statement is not empty

Page 6: The C# language fundamentals ( II ) Po Feng, Tsai

Loops The while loop

Example

Page 7: The C# language fundamentals ( II ) Po Feng, Tsai

Exercise 7 Please try to use the while loop to pri

nt the following message * ** *** **** *****

Debugger

Page 8: The C# language fundamentals ( II ) Po Feng, Tsai

Loops The do…while loop

Example

Page 9: The C# language fundamentals ( II ) Po Feng, Tsai

Loops The for loop

Example

remainder

Page 10: The C# language fundamentals ( II ) Po Feng, Tsai

Exercise 8

Please try to use the for loop to print the following message * ** *** **** *****

Page 11: The C# language fundamentals ( II ) Po Feng, Tsai

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

Page 12: The C# language fundamentals ( II ) Po Feng, Tsai

Alarm system (3-15)

Page 13: The C# language fundamentals ( II ) Po Feng, Tsai

Exercise 9

Please implement a multiplication table (3x9) with any of the loops mentioned above

Page 14: The C# language fundamentals ( II ) Po Feng, Tsai

The ternary operatorUsage

Example

Page 15: The C# language fundamentals ( II ) Po Feng, Tsai

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

Page 16: The C# language fundamentals ( II ) Po Feng, Tsai

Example 1

Page 17: The C# language fundamentals ( II ) Po Feng, Tsai

Example 2

Page 18: The C# language fundamentals ( II ) Po Feng, Tsai

#region

Used to mark off areas of code and collapse them Paired with #endregion Additional information can be attached ri

ght after the label

Page 19: The C# language fundamentals ( II ) Po Feng, Tsai

Click here

Click here