Drawing for loop steps

edited July 2017 in Programming Questions

Is it possible to draw every step of a for loop?

Tagged:

Answers

  • Answer ✓

    draw() is a while loop and its last step is to update the sketch before repeating itself again. If you set a for loop inside draw, The for loop must execute to completion in each cycle of the draw().

    If you want to see the following code step by step

    for(int step=0;step<width;step++){
      point(step,height/2);
    }
    

    I would do it this way

    int step=0;
    void draw(){
        point(step++,height/2);
        if(step==width){
           step=0;
        }
    }
    

    In other words, a for loop become a while loop... sort of.

    Kf

Sign In or Register to comment.