While loops

How do I get the loop to end when it either
Hits 10 on the counter
OR
I say something other than Y(or y)

 
  while((program_counter < 10) %% (retry == 'Y' || retry == 'y'))
Change the %% to &&.
while(condition_is_true){do something;
if(goal_achivied)do something to halt the loop}

ex:

1
2
3
n=1;

while(n<10){n++;} //this when n is smaller than 10, it will execute n++ until it reach 9 and stop 


1
2
3
while(n>0){do something here ;//as long as n is bigger than 0}
if(goal_finished){do something here;
break; //to halt loop} 


while(condition){do .... }

so as long as the condition is TRUE, then it will executed to do something. And if the condition is FALSE, then it will stop to executing the program, and skip it.
Topic archived. No new replies allowed.