COMP 170 1.0
  • Index
  • Site
      • 1. Context
        • 1.1. Motivation for This Book
        • 1.2. Resources Online
        • 1.3. Downloading and Reading Options
        • 1.4. Computer Science, Broadly
        • 1.5. Chapter Review Questions
      • 2. C# Data and Operations
        • 2.1. A Sample C# Program
        • 2.2. Lab: Editing, Compiling, and Running with Xamarin Studio
        • 2.3. Arithmetic
        • 2.4. Variables and Assignment
        • 2.5. Syntax Template Typography
        • 2.6. Strings, Part I
        • 2.7. Writing to the Console
        • 2.8. C# Program Structure
        • 2.9. Combining Input and Output
        • 2.10. String Special Cases
        • 2.11. Substitutions in Console.WriteLine
        • 2.12. Value Types and Conversions
        • 2.13. Learning to Solve Problems
        • 2.14. Lab: Division Sentences
        • 2.15. Chapter Review Questions
      • 3. Defining Functions of your Own
        • 3.1. A First Function Definition
        • 3.2. Multiple Function Definitions
        • 3.3. Function Parameters
        • 3.4. Multiple Function Parameters
        • 3.5. Returned Function Values
        • 3.6. Two Roles: Writer and Consumer of Functions
        • 3.7. Local Scope
        • 3.8. Static Variables
        • 3.9. Not using Return Values
        • 3.10. Library Classes
        • 3.11. Static Function Summary
        • 3.12. Chapter Review Questions
      • 4. Basic String Operations
        • 4.1. String Indexing
        • 4.2. Some Instance Methods and the Length Property
        • 4.3. A Creative Problem Solution
        • 4.4. Lab: String Operations
        • 4.5. Chapter Review Questions
      • 5. Decisions
        • 5.1. Conditions I
        • 5.2. Simple if Statements
        • 5.3. if-else Statements
        • 5.4. More Conditional Expressions
        • 5.5. Multiple Tests and if-else Statements
        • 5.6. If-statement Pitfalls
        • 5.7. Compound Boolean Expressions
        • 5.8. Nested if Statements
        • 5.9. Chapter Review Questions
      • 6. While Loops
        • 6.1. While-Statements
        • 6.2. While-Statements with Sequences
        • 6.3. Interactive while Loops
        • 6.4. Short-Circuiting && and ||
        • 6.5. While Examples
        • 6.6. More String Methods
        • 6.7. User Input: UI
        • 6.8. Greatest Common Divisor
        • 6.9. Do-While Loops
        • 6.10. Number Guessing Game Lab
        • 6.11. Chapter Review Questions
      • 7. Foreach Loops
        • 7.1. foreach Syntax
        • 7.2. foreach Examples
        • 7.3. Chapter Review Questions
      • 8. For Loops
        • 8.1. For-Statement Syntax
        • 8.2. Examples With for Statements
        • 8.3. Lab: Loops
        • 8.4. Chapter Review Questions
      • 9. Files, Paths, and Directories
        • 9.1. Files As Streams
        • 9.2. Writing Files
        • 9.3. Reading Files
        • 9.4. Path Strings
        • 9.5. Directory Class
        • 9.6. File Class
        • 9.7. Command Line Execution
        • 9.8. FIO Helper Class
        • 9.9. Chapter Review Questions
      • 10. Arrays
        • 10.1. One Dimensional Arrays
        • 10.2. Musical Scales and Arrays
        • 10.3. Linear Searching
        • 10.4. Sorting Algorithms
        • 10.5. Binary Searching
        • 10.6. Lab: Arrays
        • 10.7. Lab: Performance
        • 10.8. Multi-dimensional Arrays
        • 10.9. Chapter Review Questions
      • 11. Lists
        • 11.1. List Syntax
        • 11.2. .Net Library (API)
        • 11.3. Chapter Review Questions
      • 12. Dictionaries
        • 12.1. Dictionary Syntax
        • 12.2. Dictionary Efficiency
        • 12.3. Dictionary Examples
        • 12.4. Lab: File Data and Collections
        • 12.5. Chapter Review Questions
      • 13. Classes and Object-Oriented Programming
        • 13.1. A First Example of Class Instances: Contact
        • 13.2. Class Instance Examples
        • 13.3. The Rational Class
        • 13.4. Planning A Class Structure
        • 13.5. Classes And Structs
        • 13.6. Defining Operators (Optional)
        • 13.7. Chapter Review Questions
      • 14. Testing
        • 14.1. Assertions
        • 14.2. Attributes
        • 14.3. Testing the Constructor
        • 14.4. Testing Rational Comparisons
        • 14.5. Testing Rational Arithmetic
        • 14.6. Testing Rational Conversions (to other types)
        • 14.7. Testing the Parsing Feature
        • 14.8. Running the NUnit Tests
      • 15. Interfaces
        • 15.1. Rationals Revisited
        • 15.2. Csproject Revisited
        • 15.3. Chapter Review Questions
      • 16. Recursion
      • 17. Data Structures
      • 18. Appendix
        • 18.1. Development Tools
        • 18.2. Xamarin Studio
        • 18.3. Command Line Introduction
        • 18.4. Precedence of Operators
        • 18.5. Homework: Grade Calculation
        • 18.6. Homework: Grade Calculation from Individual Scores
        • 18.7. Homework: Grade File
        • 18.8. Homework: Book List
        • 18.9. Group Project
        • 18.10. Lab: Version Control
        • 18.11. Mercurial and Teamwork
        • 18.12. Acknowledgments
  • Page
      • 6. While Loops
  • Source

6. While LoopsΒΆ

  • 6.1. While-Statements
    • 6.1.1. Sum To n
  • 6.2. While-Statements with Sequences
    • 6.2.1. One Character Per Line
      • 6.2.1.1. String Backwards Exercise/Example
    • 6.2.2. Print Vowels Function
    • 6.2.3. IsDigits Function
    • 6.2.4. Play Computer With a Loop
      • 6.2.4.1. Duplicate Character Exercise
  • 6.3. Interactive while Loops
    • 6.3.1. Agree Function Exercise
    • 6.3.2. Interactive Sum Exercise
    • 6.3.3. Safe Whole Number Input Exercise
  • 6.4. Short-Circuiting && and ||
  • 6.5. While Examples
    • 6.5.1. Bisection Method
    • 6.5.2. Savings Exercise
    • 6.5.3. Strange Sequence Exercise
    • 6.5.4. Roundoff Exercise II
  • 6.6. More String Methods
    • 6.6.1. Count Repetitions in a String Exercise
    • 6.6.2. Safer PromptInt and PromptDouble Exercise
    • 6.6.3. Safest PromptInt Exercise
  • 6.7. User Input: UI
  • 6.8. Greatest Common Divisor
    • 6.8.1. Euclid’s Algorithm
    • 6.8.2. GCD “Brute Force” Method
      • 6.8.2.1. Brute-Force GCD Exercise
    • 6.8.3. GCD Subtraction Method
    • 6.8.4. GCD Remainder Loop
    • 6.8.5. Preview: Recursive GCD
  • 6.9. Do-While Loops
    • 6.9.1. Loan Table Exercise
  • 6.10. Number Guessing Game Lab
    • 6.10.1. Part 1: No Hints; Fixed Secret Number
    • 6.10.2. Part 2: Add Hints
    • 6.10.3. Part 3: Add a Random Secret Number
    • 6.10.4. Part 4: Let the Player Set the Range of Values
    • 6.10.5. Part 5: Count the Guesses
    • 6.10.6. Possible Extra Credit Improvements or Variations
  • 6.11. Chapter Review Questions

Back to top

© Copyright 2015, Andrew N. Harrington and George Thiruvathukal.
Last updated on 24-January-2016 09:35:25.