0

while loops

it's kind of confusing, i don't understand it

24th Jun 2025, 9:10 PM
Nafisah Ogunfemi
Nafisah Ogunfemi - avatar
2 Réponses
+ 3
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
24th Jun 2025, 10:58 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 1
think of it as a rearranged version of the for-loop. pseudocode: for( i=0; i<10; i++){ do things; } i=0; while(i<10){ do things; i++; }
25th Jun 2025, 4:09 AM
Bob_Li
Bob_Li - avatar