Programming is an increasingly important skill, whether you aspire to a career in software development, or in other fields. This course is the first in the specialization Introduction to Programming in C, but its lessons extend to any language you might want to learn. This is because programming is fundamentally about figuring out how to solve a class of problems and writing the algorithm, a clear set of steps to solve any problem in its class. This course will introduce you to a powerful problem-solving process—the Seven Steps—which you can use to solve any programming problem. In this course, you will learn how to develop an algorithm, then progress to reading code and understanding how programming concepts relate to algorithms.

SS

I love the focus of this first course in the specialization is about problem solving and developing a mindset for programming. The course is well thought out and concepts are clearly explained!

AM

Apr 08, 2019

Filled StarFilled StarFilled StarFilled StarFilled Star

Really great course. Took this as a refresher. I feel that the content of this course was significantly higher quality than the programming tuition I received in first semester of university.

レッスンから

Reading Code

In this module, you will learn to read code—this means you will be able to execute a piece of code by hand, and clearly illustrate what each statement does and what the state of the program is. Understanding how to read code is the only way to be sure you can write correct code. By the end of this module, you will be able to read and understand code with functions, conditional statements, iteration, and other fundamental techniques.

講師

Andrew D. Hilton

Associate Professor of the Practice

Genevieve M. Lipp

Assistant Professor of the Practice

Anne Bracy

Senior Lecturer

字幕

In this video, we're going to execute equivalent For loop and While loop code. A for loop is sometimes called syntactic sugar because it allows you to write a more compact code for counting, a common programming idiom. Let's look at their similar anatomy, both have an initialization statement. In the for loop, it follows the for keyword and then the equivalent while loop, it is just before the beginning of the while loop. The conditional expression is the second piece, following the for keyword and the piece inside parentheses after the while keyword. The increment statement is the third piece following the for keyword but an equivalent while loop would increment inside the loop body just before the close curly brackets. Finally, any statements that happen in the body of the for loop could also happen in a while loop before the increment statement. Let's see these two equivalent loops in action. As always, we begin with our execution arrow inside main. We initialize y to one and n to three. Now, the syntax of the for loop has the int i = 1 initialization just after the for keyword, so we'll pause the execution arrow there as the while execution arrow on the right enters the open curly brace and initializes i, changing the state of our program in the same way. The purpose of the curly braces is subtle. Since scope of variable i is limited to the for loop, the curly braces restrict the scope of variable i to this box. Otherwise, its scope would be the whole main function and it would not be equivalent to the for loop version. Looking at the conditional expression, we see 1 < 3 is true, so we enter the loop and begin executing statements there. Y times i is 1 times 1 which is 1. Next, we'll increment i to 2 and return to the top of the loop. Checking the conditional expression 2 < 3 is true, so we enter the loop and evaluate y times i which is 1 times 2, assigning 2 to y. We'll increment i to 3 and return to the top of the loop, 3 < 3 is false, so we move the execution arrow to just after the loop. Respecting the scope of i in the for loop, we also exit the curly brace after the while loop, destroying the box for i since it is now out of scope. Finally, we return zero and exit main.