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 Bool Variables

3 Bool Variables Variables that hold the value true or false

4 Bool Variables Variables that hold the value true or false
They do not hold numbers

5 Bool Variable Example

6 Bool Variable Example bool enteredRightAnswer;

7 Bool Variable Example bool enteredRightAnswer;
enteredRightAnswer = false;

8 Bool Variable Example bool enteredRightAnswer;
enteredRightAnswer = false;

9 Bool Variable Example bool enteredRightAnswer;
enteredRightAnswer = false; if (enteredRightAnswer == true )

10 Bool Variable Example bool enteredRightAnswer;
enteredRightAnswer = false; if (enteredRightAnswer)

11 Bool Variable Example bool enteredRightAnswer;
enteredRightAnswer = false; if (enteredRightAnswer) { Console.WriteLine(“Good job! That was a hard one!”); }

12 The While Loop

13 The While Loop while ( some condition is true ) { do a bunch of stuff
somehow condition becomes false }

14 The While Loop while ( some condition is true ) { do a bunch of stuff
somehow condition becomes false }

15 The While Loop while ( some condition is true ) { do a bunch of stuff
somehow condition becomes false }

16 The Anatomy of the While Loop

17 The Anatomy of the While Loop
while ( loop condition ) { loop body }

18 The Anatomy of the While Loop
while ( loop condition ) { loop body }

19 The Anatomy of the While Loop
while ( loop condition ) { loop body }

20 The Anatomy of the While Loop
while ( loop condition ) { loop body }

21 The Anatomy of the While Loop
while ( loop condition ) { loop body }

22 Sentry Variables

23 Sentry Variables Variables that determine if keep looping or not

24 Sentry Variables Variables that determine if keep looping or not
Also called “loop control variable”

25 Sentry Variables Variables that determine if keep looping or not
Also called “loop control variable” A critical part of all loops

26 Sentry Variables

27 Sentry Variables Remember this:

28 Sentry Variables Remember this: Initialize

29 Sentry Variables Remember this: Initialize, check

30 Sentry Variables Remember this: Initialize, check, change

31 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop:

32 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable

33 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable If you don’t you likely won’t be able to get into the loop

34 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable If you don’t you likely won’t be able to get into the loop Check the sentry variable in the loop condition:

35 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable If you don’t you likely won’t be able to get into the loop Check the sentry variable in the loop condition: If you don’t, you will have an infinite loop

36 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable If you don’t you likely won’t be able to get into the loop Check the sentry variable in the loop condition: If you don’t, you will have an infinite loop Change the sentry variable in the loop body:

37 Sentry Variables Remember this:
Initialize, check, change Initialize the sentry variable before the loop: Put a appropriate starting value in the sentry variable If you don’t you likely won’t be able to get into the loop Check the sentry variable in the loop condition: If you don’t, you will have an infinite loop Change the sentry variable in the loop body:

38 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

39 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

40 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

41 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

42 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

43 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

44 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

45 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

46 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

47 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

48 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

49 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

50 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

51 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }

52 Example bool validInput; // create sentry
validInput = false; // initialize sentry while ( validInput == false ) // check sentry { Console.Write(“Enter your name: ”); name = Console.ReadLine(); if ( name != “” && name.ToLower() != “tom”) validInput = true; // change sentry }


Download ppt "Welcome back to Software Development!"

Similar presentations


Ads by Google