Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion on adding an explanation about the for loop in page 2 #41

Open
akarsh opened this issue Nov 1, 2017 · 5 comments
Open

Suggestion on adding an explanation about the for loop in page 2 #41

akarsh opened this issue Nov 1, 2017 · 5 comments

Comments

@akarsh
Copy link

akarsh commented Nov 1, 2017

Suggestion about explaining the for loop in the loop. As, the while loop does not yield in a 20x20 grid in my case.


Only using the for loop worked out.

@xMartin
Copy link
Member

xMartin commented Nov 1, 2017

Thanks for your suggestion! The while loop just definitely do the trick and the syntax is easier so we decided to prefer it compared to the for loop.

But it's interesting to know that the for loop worked better for you. Actually, although the while loop loop looks easier a lot of people don't think about the incrementing of the counter. Maybe that's more obvious with the for loop?

Let's keep it open for discussion or better: test it out at the next workshop!

@akarsh
Copy link
Author

akarsh commented Sep 25, 2019

I got this today at the meet-up. The learner finds using for loop easily. The while loop seems hard to get around.

@CarlosColumbus
Copy link

Hello there,
i am a really beginner and trying to solve the excercise with the while loop (make 20x20 grid) but it didnt work. Have someone pls the solution for this excercise for me? Thanks a lot

@xMartin
Copy link
Member

xMartin commented Dec 2, 2019

One solution would be

function drawing() {
  color("red");
  var row = 0;
  while (row < 20) {
    var column = 0;
    while (column < 20) {
      circle(column * 10, row * 10, 4);
      column = column + 1;
    }
    row = row + 1;
  }
}

or slightly different but doing exactly the same:

function drawing() {
  color("red");
  var row = 0;
  var column = 0;
  while (row < 20) {
    while (column < 20) {
      circle(column * 10, row * 10, 4);
      column = column + 1;
    }
    column = 0;
    row = row + 1;
  }
}

@akarsh
Copy link
Author

akarsh commented Dec 3, 2019

The second solution is not usually thought about. But shows how to manipulate the column counter. As the two variables are declared and initialized outside the loop. I vote for second solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants