While and for loop

Can someone explain me While and for loop on skype?
cause i am having hard time understanding it.

There's nothing we could say to you on Skype that we can't say here.

Do you understand "loop"? The same piece of code gets executed many times. Do you understand that?
yes i understand 'loop' very well. I just don't understand how the loop is made.

Do you understand what i just said?
I just don't understand how the loop is made.


You make it by "typing". That's touching the keys on the keyboard in front of you.

Here is how to make a while loop:

1
2
3
4
while (some_condition_is_true)
{
  // code to repeat many times
}
Last edited on
1
2
3
4
while ( <condition> )
{
   ...
}


The condition can either be true or false. While it's TRUE the loop keeps going on.

1
2
3
4
5
6
int i = 0;
while( i < 10)
{
    cout << "Hello" << endl; 
    i++;
} 


This will print Hello ten times.

i = 0 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 1 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 2 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 3 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 4 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 5 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 6 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 7 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 8 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 9 -> Less than 10? -> YES -> Execute ( print the string and INCREASE the variable i )
i = 10 -> Less than 10? -> NO -> EXIT
There is nothing we can say here that you cannot read on hundreds of web pages explaining how loops work.
PM your skype name. I can help you with this.
Topic archived. No new replies allowed.