Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome back to Software Development!

Similar presentations


Presentation on theme: "Welcome back to Software Development!"— Presentation transcript:

1 Welcome back to Software Development!

2 Due Today… Reading assignment: Clear/Unclear windows on pages 87-97

3 Tomorrow…

4 Tomorrow… Test on loops

5 Loops Review

6 Loops Review 3 types of loops:

7 Loops Review 3 types of loops: while

8 Loops Review 3 types of loops: while
used when you don’t know how many times to loop

9 Loops Review 3 types of loops: while for
used when you don’t know how many times to loop for

10 Loops Review 3 types of loops: while for
used when you don’t know how many times to loop for used when you do know how many times to loop

11 Loops Review 3 types of loops: while for foreach
used when you don’t know how many times to loop for used when you do know how many times to loop foreach

12 Loops Review 3 types of loops: while for foreach
used when you don’t know how many times to loop for used when you do know how many times to loop foreach used to work on parts of a group, one at a time

13 All Loops…

14 All Loops… Use a sentry variable

15 All Loops… Use a sentry variable Also called the loop control variable

16 All Loops… Use a sentry variable First: Initialize the sentry variable
Also called the loop control variable First: Initialize the sentry variable

17 All Loops… Use a sentry variable First: Initialize the sentry variable
Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop

18 All Loops… Use a sentry variable First: Initialize the sentry variable
Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping

19 All Loops… Use a sentry variable First: Initialize the sentry variable
Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping Finally: Change (often increment) the sentry variable

20 All Loops… Use a sentry variable First: Initialize the sentry variable
Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping Finally: Change (often increment) the sentry variable If you don’t, you won’t be able to exit the loop…infinite loop

21 While Loop

22 While Loop Used when you don’t know how many times you need to loop

23 While Loop Used when you don’t know how many times you need to loop
Init the sentry variable outside and before the loop

24 While Loop Used when you don’t know how many times you need to loop
Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition

25 While Loop Used when you don’t know how many times you need to loop
Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop

26 While Loop Used when you don’t know how many times you need to loop
Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop Often increment the sentry when simply counting

27 While Loop while ( check sentry )
Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop Often increment the sentry when simply counting while ( check sentry )

28 While Loop Example int counter; // create sentry variable
counter = 0; // init sentry variable while ( counter < 5 ) // loop until counter >= 5 { Console.WriteLine(“Looped {0} times.”, counter); counter++; // increment counter }

29 For Loop

30 For Loop Used when you *do* know how many times you need to loop

31 For Loop Used when you *do* know how many times you need to loop for (

32 For Loop for ( init the sentry ;
Used when you *do* know how many times you need to loop for ( init the sentry ;

33 For Loop for ( init the sentry ; check the sentry ;
Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ;

34 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry )

35 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement:

36 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable

37 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable

38 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable 3rd part: Change the sentry variable

39 For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable 3rd part: Change the sentry variable Often increment the sentry when simply counting

40 For Loop int counter; // create sentry variable
// Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); }

41 For Loop int counter; // create sentry variable
// Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable

42 For Loop int counter; // create sentry variable
// Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable Check sentry variable

43 For Loop int counter; // create sentry variable
// Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable Check sentry variable Increment sentry variable

44 Foreach Loop

45 Foreach Loop Used to work on parts of a group, one at a time

46 Foreach Loop Used to work on parts of a group, one at a time
The sentry variable is created in the foreach statement

47 Foreach Loop Used to work on parts of a group, one at a time
The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable

48 Foreach Loop foreach ( Used to work on parts of a group, one at a time
The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach (

49 Foreach Loop foreach ( create sentry
Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry

50 Foreach Loop foreach ( create sentry in
Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry in

51 Foreach Loop foreach ( create sentry in group to work with )
Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry in group to work with )

52 Foreach Example string myString; // create sentence variable
myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); }

53 Foreach Example string myString; // create sentence variable
myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); } Create sentry variable

54 Foreach Example string myString; // create sentence variable
myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); } Create sentry variable Automagically check and change sentry variable

55 Your Task

56 Your Task Get a multi-word sentence from the user
Require that they enter a multi-word sentence Allow up to 3 tries then quit Reprint the sentence with: The first letter of every word capitalized All other letters lower case You have till the end of the period…

57 Existing Tasks Fix your MathGame program so that the user must enter a number.

58 Clear and Unclear Windows


Download ppt "Welcome back to Software Development!"

Similar presentations


Ads by Google