程序代写代做代考 c# Desktop Applications in C#

Desktop Applications in C#

Day 12 Flow Control:
More on Loops
Chewei Liu

Updates
Homework 2 due tomorrow
Review session on Monday
Review the materials
Bring your questions

Outline
Recap:
While
For
For each
Loops and Arrays
Loops and If
Lab

4
While Statement
Pretest
If the conditional expression evaluates to true, statement(s) performed
If the conditional expression evaluates to false, statement(s) skipped

4

5
For Loop

5

Foreach loops
Tie your loop execution to a collection

For each loop
foreach (variable type variable name in collection)
{
// code block
}

For each examples

For loop & arrays example

Loop & If/else

Keyword: continue & break
Continue (skip the execution of current iteration)
Break (breaks the loop)

Practice

Lab 12
1. Assume you have an integer array (int[] iSampleArray = { 2, 5, 1, 3, 4 }) and you want to
Use Foreach to print out each element great than 2

2. Sum up the first 10 numbers except for numbers that are divisible by 3
Use For-Loop
Use keyword: continue
Print out the final results

13

/docProps/thumbnail.jpeg