While and for loop

May 30, 2016 at 10:23am
Can someone explain me While and for loop on skype?
cause i am having hard time understanding it.

May 30, 2016 at 10:46am
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?
May 30, 2016 at 10:48am
yes i understand 'loop' very well. I just don't understand how the loop is made.

Do you understand what i just said?
May 30, 2016 at 10:55am
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 May 30, 2016 at 10:56am
May 30, 2016 at 10:56am
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
May 30, 2016 at 10:59am
There is nothing we can say here that you cannot read on hundreds of web pages explaining how loops work.
May 30, 2016 at 11:24am
May 30, 2016 at 9:20pm
PM your skype name. I can help you with this.
Topic archived. No new replies allowed.