How does this C for-loop print text-art pyramids?

后端 未结 10 2029
灰色年华
灰色年华 2021-02-05 04:24

This is my first time posting in here, hopefully I am doing it right.

Basically I need help trying to figure out some code that I wrote for class using C. The purpose o

10条回答
  •  一个人的身影
    2021-02-05 04:48

    for ( int tall = 0; tall < user_i; tall++ ) { ... }
    

    I think of this in natural language like this:

    1. int tall = 0; // Start with an initial value of tall = 0
    2. tall < user_i; // While tall is less than user_i, do the stuff between the curly braces
    3. tall++; // At the end of each loop, increment tall and then recheck against the condition in step 2 before doing another loop

    And with nice indentation in your code now it's much easier to see how the for loops are nested. The inner loops are going to be run for every iteration of the outer loop.

提交回复
热议问题