Busy. Please wait.
Log in with Clever

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever

Username is available taken
show password

Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.

Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
Didn't know it?
click below
Knew it?
click below
Don't Know
Remaining cards (0)
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Chapter 6

Control Statements: Part 2

1. Essentials of Counter-Controlled Repetition Counter-controlled repetition requires... 1. A control variable(or loop counter).. 2. The initial value of the control variable..
2. Essentials of Counter-Controlled Repetition 3. The increment(or decrement) by which the control variable is modified each time through the loop(also known as each iteration of the loop).. 4. The loop-continuation condition that determines whether to continue looping
for Repetition Statement Specifies the elements of counter-controlled-repetition in a single line of code. In general, counter-controlled repetition should be implemented with a for statement.
for Statement Header(for Header) The for's first line(including the keyword for and everything in parentheses after for). The for header "does it all" - it specifies each of the items needed for counter-controlled repetition with a control variavle.
1. for Statement General Format The general format of the for statement is... for(intialization; loopContinuationCondition; increment) statement...where the initialization expression names the loop's control variable and provides its initial value,
2. for Statement General Format the loopContinuationCondition is the condition that determines whether looping should continue, and the increment modifies the control variable's value(whether increment or decrement) so that the loop continuation condition eventually becomes false.
3. for Statement General Format Example:... for(int counter = 1; counter <= 10; ++counter) Console.Write("{0} ", counter);... Displays:... 1 2 3 4 5 6 7 8 9 10
Representing for Statements with Equivalent while Statement In most cases, the for statement can be represented with an equivalent while statement as follows:... initialization; while(loopContinuationCondition) { statement; increment; }
Variable's Scope Defines where it can be used in an app. For example, a local variable can be used only in the method that declares the variable and only from the point of declaration through the end of the block in which the variable has been declared.
for Statement Control Variable Scope If the initialization expression in the for header declares the control variable(the control variable's type is specified before the variable name), the control variable can be used only in that for statement - it will no exist outside it
1. Field Width We can use the format item {0, 20} to output the string "Amount on Deposit" and a nice table of values under it. The integer 20 after the comma indicates that the value output should be displayed with a field width with 20 character positions.
2. Field Width If the value to be output is less than 20 character positions wide, the value is right justified in the field by default(preceded by blanks).
3. Field Width If the value to be output were more than 20 characters wide, the field width would be extended to the right and this would upset the neat columns of our tabular output. To indicate that output should be left justified, simply use a negative field width
1. Static Methods Many classes also provide methods that perform common tasks and cannot be called on objects - they must be called using a class name.
2. Static Methods You can call a static method by specifying the class name followed by a member access(.) operator and the method name, as in... ClassName.MethodName(arguments)
Static Method Pow We use static method Pow of class Math to perform the exponential calculations. Math.Pow(x, y) calculates the value of x raised to the yth power.
Error-prevention Tip 6.5 Do not use variables of type double(or float) to perform precise monetary calculations; use type decimal instead. The imprecision of floating-point numbers ca cause errors that will result in incorrect monetary values
1. do...while Repetition Statement Is similar to the while statement. In the while statement, the app test the loop-continuation condition at the beginning of the loop, before executing the loop's body. If the condition is false, the body never executes.
2. do...while Repetition Statement The do...while statement tests the loop continuation condition after executing the loop's body; therefore, the body always executes at least once. When a do...while statement terminates, execution continues with next statement in sequence
switch Multiple-Selection Statement Performs different actions based on the possible values of an expression. Each action is associated with the value of a constant integral expression or a constant string expression that the variable or expression on which the switch is based may assume
1. End-of-file Indicator The notation Ctrl + z means to simultaneously press both the Ctrl key and the z key when typing in Command Prompt. Ctrl + z is the Windows key sequence for typing the end-of-file indicator.
2. End-of-file Indicator This is one way to inform the app that there's no more datat to input. If Ctrl+z is entered while the app is awaiting input with a ReadLine method, null is returned
Utility Method(Helper Method) When a private member is a method,it's commonly referred to as a utility method or helper method because it can be called only by other member of that class an dis used to support the operation of those other members
break Statement When executed in a while, for, do...while switch, or foreach, causes immediate exit from the statement. Execution typically continues with first statement after control statement.Used to escape early from repetition statements and skip remainder of switch
1, continuation Statement When executed in a while, for, do...while, or foreach, skips remaining statements in loop's body and proceeds with next iteration of loop. In while and do...while, app evaluates loop-continuation test immediately after continue statement executes.
2, continuation Statement In for statement, the increment expression normally executes next, then the app evaluates the loop-continuation test
Simple Conditions Are expressed in terms of the relational operators >, <, >=, and <=, and the equality operators ==, and !=. Each expression tests only one condition
1. Logical Operators C# provides logical operators to enable you to form more complex conditions by combining simple conditions. The logical operators are &&(conditional AND), ||(conditional OR), &(boolean logical AND), |(boolean logical inclusive OR),
2. Logical Operators ^(boolean logical exclusive OR), and !(logical negation)
1. Conditional AND(&&) Operator Suppose we wish to ensure at some point in an app that two conditions are both true before we choose a certain path of execution. In this case, we can use the &&(conditional AND) operators, as follows: if(gender == 'F && age >= 65') ++seniorFemales;
2. Conditional AND(&&) Operator If either or both of the simply conditions are false, the app skips the increment.
1. Conditional OR(||) Operator Suppose we wish to ensure that either or both of two conditions are true before we choose a certain path of execution. In this case, we use the ||(conditional OR) operator, as in the following app segment;
2. Conditional OR(||) Operator if((semesterAverage >= 90) || (finalExam >= 90)) Console.WriteLine("Student grade is A");. The only time the message "Student grade is A" is not displayed in when both of the simply conditions are false
Short-Circuit Evaluation The parts of an expression containing && or || operators are evaluated only until it's known whether the condition is true or false
Boolean Logical AND(&) and Boolean Logical OR(|) Operators The boolean logical AND(&) and boolean lgocial inclusive OR(|) operators work identically to the &&(conditional AND) and ||(conditional OR) operators, except the boolean logical operators always evaluate both of their operands(no short circuit evaluation)
Boolean Logical Exclusive OR(^) A complex condition containing the boolean logical exlcusive OR(^) operator(also called the logical XOR operator) is true if and only if one of its operands are true and the other false. If both are true or both are false, the entire condition is false.
Logical Negation(!) Operator The !(logical negation or not) operator enables you to "reverse" meaning of condition. Unary operator with single condition as an operand. Is placed before a condition to choose a path of execution if original condition(without logical negation) is false
Rules for Forming Structured Apps 1. Begin with the simplest activity diagram.. 2. Any action state can be replaced by two action states in sequence.. 3. Any action state can be replaced by any control statement.. 4. Rules 2 and 4 can be applied as often as necessary in any order
Structured Programming Summary Structured programming promotes simplicity. Research has shown that only three forms of control are needed to implement any algorithm... 1. Sequence.. 2. Selection.. 3. Repetition
Sequence Sequence is trivial. Simply list the statements of the sequence in the order in which they should execute. Selection is implemented in one of three ways... 1. if statement.. 2. if...else statement.. 3. switch statement
Repetition Repetition is implemented in four ways... 1. while statement.. 2. do...while.. 3. for statement.. 4. foreach statement
Created by: TimC#Programming
Popular Engineering sets




Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
restart all cards