Questions? Email

Join our weChat group or follow us on Facebook

©2019 by Legion of Learners

7 days ago

5.2 - How to repeat some actions N times?


Edited: 6 days ago

A. Introduction

The third and last type of flow is all about repetitions: how to repeat some actions exact N times? or how to repeat some actions until certain status is achieved? There are actually three types of statements: for loops, while loops and do loops.

B. Watch(Slides)

C. Try: Print out a multiplication table from 1 x 1 = 1 .... to 9 x 9 = 81. (Hint: you need a for loop inside a for loop)

New Posts
  • sfolax6776
    Nov 1

    A. Introduction You were asked to use for-loops to print out a multiplication table, for-loops and nested for-loops are widely used for many applications. Here are some examples. B. Watch( Slides ) C. Try to print out the upper half or the lower half of a multiplication table like this:
  • sfolax6776
    Oct 26

    A. Introduction do loops are essentially same at while loops except that they will run at least once. All three types of loops can be converted into each other... Which one to choose? B. Watch( slides ) C. Try this: Write a do loop that reads integers and computes their sum. Stop when reading a zero or the same value twice in a row. For example, if the input is 1 2 3 4 4, then the sum is 14 and the loop stops.
  • sfolax6776
    Oct 26

    A. Introduction There are probably millions of programs in the world now, but all programs are made of three different "flows", or control structures: sequential, branching and looping. Sequential execution goes from top to bottom, line by line. Branching execution allows you to make decisions based on a condition: You can even embed a branching structure in one branch: Or, making one decision right after another: B. So what's the third and last type of flow (control structure)? C. Try to write some pseudo code to add all even numbers between 200 and 300.