We need loops to repeat one action multiple times.
Syntax:
for(variable, which we will change; condition; change variable)
{
//code to repeat
}
Example:
int a=0;
for(int i=0; i<10; i++)
{
a=a+1;
}
This code will add to a '1' 10 times, so at the end of our loop a will be equal '10'.
No comments:
Post a Comment