0
while loops
it's kind of confusing, i don't understand it
2 Respuestas
+ 2
in short: while this is true, do something. If it's not true, it gets skipped
while (this is true) {
doSomething();
}
while I'm still dirty, shower
once I'm clean, i don't need to shower anymore so I'll move on with my day
If i was already clean, i can skip the shower
while (me.dirty == true) {
continueShower();
}
// move on with my day
while he is talking, listen
when he is done talking, listening is not required
If he wasn't talking in the first place, skip listening
while (he.isTalking == true) {
listen();
}
// don't have to listen to him
if the condition is false, then nothing happens
// he is not talking
he.isTalking = false
// i dont have to listen because he isn't talking
while(he.isTalking == true) listen();
// move on
0
if you understand for loops, think of it as a rearranged version of it.
pseudocode:
for( i=0; i<10; i++){
do things;
}
i=0;
while(i<10){
do things;
i++;
}