While loop inside of a while loop.
in
Programming Questions
•
1 year ago
hello there,
I 'm newbiee in processing. Actually programming, too.
I'm trying so hard to understanding about while loop, inside of a while loop.
I know a while loop does its job until predicted condition is false, but what about second while loop ?
Here is the code i am working on it.
---------------------------------------------------
---------------------------------------------------
float x = 0 ;
float y = 0;
void setup() {
size (400, 400);
background(255);
noStroke();
}
void draw() {
fill(0);
while (x < width) { // if x smaller than width
while (x> width) { // x = 0 when program start, so i assumed that processing skip that while loop.
y = y + 17 ; // if x greater than width, y must be +17.
}
rect(x, y, 15, 15); //draw 15*15 rectangle at x,y positions
x = x + 17;
}
}
float y = 0;
void setup() {
size (400, 400);
background(255);
noStroke();
}
void draw() {
fill(0);
while (x < width) { // if x smaller than width
while (x> width) { // x = 0 when program start, so i assumed that processing skip that while loop.
y = y + 17 ; // if x greater than width, y must be +17.
}
rect(x, y, 15, 15); //draw 15*15 rectangle at x,y positions
x = x + 17;
}
}
---------------------------------------------------
---------------------------------------------------
This is my logical explaining why i write code like that. But,
the code is drawing only first line of canvas. So ...hmm...
Could someone explain me what is the logic behind a while loop inside of a while loop ?
Thank you.
1