While loops

May 14, 2014 at 2:27am
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'))
May 14, 2014 at 2:36am
Change the %% to &&.
May 14, 2014 at 6:01pm
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.