why this idea in using while loop. is it trivial? -
i have met lot reading other people's scripts. short example below: need input , store them in var , b, scheme below:
int ok; ok = false; while(!ok){ //ask input //ask input b ok = true; } i understand wants, why scheme necessary? can have "ask input , b".
but why scheme necessary?
it not necessary.
can have "ask input , b".
you sure can.
however, if user gives input not useful (for example: ask users age, , type "horse"), might want ask again. allowing re-trying of input useful feature. canonical control structure repeating piece of program loop.
your example program however, sets ok unconditionally, in case there no use loop. loop makes sense if there form of validation must passed before input ok.
Comments
Post a Comment