1 00:00:00,640 --> 00:00:04,280 Pseudo code expresses code logic in procedures using plain verbs and 2 00:00:04,280 --> 00:00:05,980 nouns from spoken language. 3 00:00:05,980 --> 00:00:09,280 When you write pseudo code, you explain each step in the program. 4 00:00:09,280 --> 00:00:10,790 Think of it kinda like a recipe. 5 00:00:10,790 --> 00:00:12,770 A program usually has some data, or ingredients, 6 00:00:12,770 --> 00:00:18,150 that are acted upon just like you peel, mix, whisk, eat and bake while cooking. 7 00:00:18,150 --> 00:00:21,650 A recipe lists the exact order in which to perform each step. 8 00:00:21,650 --> 00:00:22,490 If you bake, for 9 00:00:22,490 --> 00:00:25,440 example, before you mix the batter, your cake won't turn out right. 10 00:00:26,620 --> 00:00:30,830 You can write pseudo code on paper with a pen, or open up a text editor and 11 00:00:30,830 --> 00:00:34,300 use code comments to describe your program's logic in pseudo code. 12 00:00:34,300 --> 00:00:35,550 Let me walk you through an example. 13 00:00:36,760 --> 00:00:40,120 For any programming project, we usually start with a set of requirements. 14 00:00:40,120 --> 00:00:42,540 These requirements, like a set of instructions, 15 00:00:42,540 --> 00:00:44,720 tell you how the program should perform. 16 00:00:44,720 --> 00:00:48,034 They'll often want some input, like retrieving two numbers from a user and 17 00:00:48,034 --> 00:00:51,260 some kind of output like the result of adding those two numbers together. 18 00:00:52,680 --> 00:00:55,820 You can use those requirements to guide the design of your program and 19 00:00:55,820 --> 00:00:57,710 the pseudo code you write. 20 00:00:57,710 --> 00:01:00,290 In this example, we'll take a simple specification and 21 00:01:00,290 --> 00:01:03,260 convert it into programming steps using pseudo code. 22 00:01:03,260 --> 00:01:07,270 If you'd like to follow along, open the work space associated with this video, and 23 00:01:07,270 --> 00:01:09,995 the file print underscore sum dot txt. 24 00:01:09,995 --> 00:01:16,670 [SOUND] Get two integer values from a user and output the sum of those numbers. 25 00:01:16,670 --> 00:01:22,092 In other words, get two numbers, add them together and output the results. 26 00:01:22,092 --> 00:01:23,517 The requirement is simple, but 27 00:01:23,517 --> 00:01:26,540 a program would need to perform several steps to complete the task. 28 00:01:27,740 --> 00:01:30,990 First, you need to prompt the user to type a number. 29 00:01:30,990 --> 00:01:32,520 That's one step. 30 00:01:32,520 --> 00:01:34,780 Then you create a variable to store the input. 31 00:01:36,380 --> 00:01:42,800 Prompt for another number, store that number in a variable named num2. 32 00:01:42,800 --> 00:01:46,150 Create another variable with the sum of the two values. 33 00:01:46,150 --> 00:01:49,840 And finally, print the value inside the sum variable. 34 00:01:49,840 --> 00:01:51,670 That's an example of pseudo code. 35 00:01:51,670 --> 00:01:52,910 It reads easily and 36 00:01:52,910 --> 00:01:55,330 could be used by a programmer coding in any programming language. 37 00:01:56,370 --> 00:01:58,170 This example is simple, but 38 00:01:58,170 --> 00:02:01,500 you can use pseudo code to describe any programming concept. 39 00:02:01,500 --> 00:02:04,320 For example, here's how you could add a conditional statement to make sure 40 00:02:04,320 --> 00:02:07,560 the input from the user was a number and not a letter. 41 00:02:07,560 --> 00:02:10,858 Here, I've added conditional statements to check and see if the input is a number. 42 00:02:10,858 --> 00:02:14,490 Notice that I've added indentation to show the code that runs 43 00:02:14,490 --> 00:02:16,310 inside the conditional statement. 44 00:02:16,310 --> 00:02:18,195 In other words, if that condition is true, 45 00:02:18,195 --> 00:02:20,180 then the steps that are indented would happen. 46 00:02:21,440 --> 00:02:24,710 To mark the end of a conditional statement add endif. 47 00:02:24,710 --> 00:02:28,770 This makes clear where the condition ends and the rest of the program continues. 48 00:02:28,770 --> 00:02:32,610 You can easily create conditional statements with multiple conditions too. 49 00:02:32,610 --> 00:02:35,090 Pseudo code is simple and straightforward. 50 00:02:35,090 --> 00:02:38,640 You can easily see the logic and you never get a syntax error. 51 00:02:38,640 --> 00:02:40,610 In the next video, I'll show you pseudo code for 52 00:02:40,610 --> 00:02:44,020 describing other programming concepts like loops and functions.