280 likes | 364 Views
CIS 199 Test 02 Review. Loops. for “For a given value X, while X is true, modify X…” while “While X is true…” do – while “Do these tasks, while X is true…” foreach “For every X in this set of Y do the following…”. for Example. while Example. do while Example. foreach Example.
E N D
Loops • for • “For a given value X, while X is true, modify X…” • while • “While X is true…” • do – while • “Do these tasks, while X is true…” • foreach • “For every X in this set of Y do the following…”
Key Loop Details • Loops are NOT guaranteed to execute at least once! • …only exception is ‘do while’ • ‘for’ loops require a variable, condition, and ‘step’ instruction • ‘while’, ‘do while’ loops require a boolean expression • ‘foreach’ loops require a collection of items • Arrays • Lists • Generic Collections
Files • OpenFileDialog • Used to load file from location • SaveFileDialog • Used to select file save location • BOTH very User friendly!
Random Numbers in C# • Provided from: System.Random • Is ONLY pseudo-random • Produces a finite set of values with equal probability • Not truly random, follows a mathematical algorithm • Created with OR without seed value • Common methods used: • Next() • Next(int) • Next(int, int) • NextDouble()
Methods • Actions, code to be executed • May return a value, may take value (not required) • Can be controlled via scope keywords • Can be static
Methods &Modularizing Your Code • Methods • Break out ‘steps’ • Easier to test • Easier to visualize
The ‘switch’ statement can replace nested if/else. But under what conditions? • When matching on a specific… • Value • Type • Enumeration • …other data
What does a ‘break’ statement do in a loop? • It stops (BREAKS) loop execution • Code continues, no further loop iterations
What does a ‘continue’ statement do in a loop? • Goes to the next iteration • CONTINUES loop execution, by skipping current iteration
What are preconditions and postconditions for a method? • PRECONDITIONS • Conditions that MUST be TRUE before method execution • POSTCONDITIONS • Conditions that WILL be TRUE after method execution
What is the difference between a void method and a value-returning method? • VOID Method • Returns nothing! • …a void return. • Value-Returning • Returns a value! • …that’s not a void return.
Compare and contrast the use of pass by value against pass by reference, using key word ref versus pass by reference using keyword out. • Pass by Value • Passes a copy of the value • Not the object itself • Pass by Reference • Passes the actual object itself • ‘ref’ • Causes a pass by reference on a variable • ‘out’ • Is used to reference a variable that the method will update
How can REACH further help you today? • Ask Questions Now! • Need to see an Example? • Need to see a concept again? • Need additional help? • Visit us at: • iTech Zone • CRC (Ekstrom Library) • Monday-Thursday8:00am – 8:00pm • Friday8:00am – 4:00pm • Sunday12:00pm – 2:00pm (CRC Only)