The while() and do…while() iteration statements.
These statements operate same way that for() statements operate. The main difference is that a for() statement is best used when there are a particular number of iterations needed through a code block, but while() and do…while() are the best when a single expression needs to be evaluated and continuing the loop so long as it evaluates as true.
While() loop syntax
// continue doing something while the above expression is true.
do...while() loop syntax:
// do something atleast once.
// while the expression below is true.
Let's us consider ToluVsMoniGame: Here I will show how both while(),and do while() loops could be use.
1.This should allow users inputs.
2.Substract user input A from random number.
3.Store user inputs in as a string.
4.Check if input A and B after some evaluations is still greater than 0, if yes do some more evaluations.
5.Set up the battle logic.
Set up the programmatic ID: