Preview

Programming in C#

Satisfactory Essays
Open Document
Open Document
606 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Programming in C#
Short-circuiting logical operators
&& and ||
OR (||) expressions – if the first evaluates as true, no need to evaluate the second operand
AND (&&) expressions – if the first evaluates as false, no need to evaluate second operand
C# also includes the & and | operators logical does not perform short-circuit evaluation

NESTED-IF ELSE STATEMENT * Acceptable to write an if within an if * When block is completed, all remaining conditional expressions are skipped or bypassed * Syntax for nested if…else follows that of two-way * Difference: With a nested if…else, the statement may be another if statement * No restrictions on the depth of nesting
Limitation comes in the form of whether you and others can read and follow your code
SWITCH STATEMENT * Multiple selection structure * Also called case statement * Works for tests of equality only * Single variable or expression tested * Must evaluate to an integral or string value * Requires the break for any case * No fall-through available
PRECEDENCE OF THE OPERATORS * Associativity * Left-associative * All binary operators except assignment operators * Right-associative * Assignment operators and the conditional operator ? * Operations are performed from right to left * Order changed through use of parentheses
LOOPING STATEMENTS
Types of loops * while * Counter-controlled * Sentinel-controlled * State-controlled * for * foreach * do…while

1. WHILE STATEMENT * Simplest and most frequently used loop * Syntax : while (conditional expression) statement(s); * Expression – sometimes called loop condition * Returns a Boolean result of true or false * No semicolon after the conditional expression * Null body→ empty bodied loop→ infinite loop * Enclose multiple statements for body in { }

a. COUNTER-CONTROLLED LOOP *

You May Also Find These Documents Helpful

Related Topics