From the course: Practice It: C Decisions and Loops

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Check it: Reviewing high scores

Check it: Reviewing high scores - C Tutorial

From the course: Practice It: C Decisions and Loops

Check it: Reviewing high scores

- [Instructor] Welcome back. I hope you managed to beat your own high score and without cheating. Converting a while loop into a for loop and vice versa is rather easy, providing that the code runs and that you can identify all the parts. So here are the parts. Line 11, initialization, line 12, condition, line 15, iteration action. These lines are edited down into a single for loop statement. for x = 0. The semicolon is already in place. I can join the next line. And there's the looping condition, semicolon, and then add line 14, x++, the trigger, remove it from here. There's the loop. The braces are unnecessary, but I'll keep them anyway. And there's the output. Within the code, I follow a more traditional C format when I declare all the variables up top in a function. You can, however, declare a variable anytime before it's used. Often in a for loop, you see other programmers do this. And of course I can…

Contents