- Code: Select all
while(condition is true)
{
// do something
}
So if you wanted to simulate a for loop you could do it like this.
- Code: Select all
int i=0;
while(i<10)
{
// do something
i++;
}
Just make sure the while loop is escapable. There is also do while, which runs the code first, and then checks if it needs to loop.
- Code: Select all
do
{
// do something
}while(condition);
// notice, you need the semicolon after this while (but not the other)