Loops C++

Jun 10, 2014 at 12:40pm
Should i really need to master loops (while,for,do while) in C++ ?
I get it but when im trying some beginner exercises i cannot do it.
all i can do is looping numbers and its square.
Jun 10, 2014 at 12:48pm
Should i really need to master loops

Yes.

Standard library does provide several algorithms that do loops on your behalf, but they do not apply to every situation. Furthermore, understanding the concept of iterative algorithm (aka loops) is extremely useful.
Jun 10, 2014 at 6:26pm
trust me you want to master them...thumb rule for loops:

While loop - use when number of executions(iteration) is unknown

for loop - use when number of executions is known, mostly use with arrays

do while - use when you want to execute some code once regardless
of your condition being true or false

you will use them with almost everything because 90% problems are logic based and there is no other way of doing them without loops and condition statements(if/else).
Last edited on Jun 10, 2014 at 6:30pm
Jun 10, 2014 at 10:26pm
Loops are one of the most fundamental concepts of programming. So yes, you need to master it.

What are you having problems with in particular? Would be more than happy to help.
Jun 11, 2014 at 10:48am
I get it but i really do not know my problem in loops. like what i said all i can do is looping numbers :( Can someone give me exercises hehe
Jun 11, 2014 at 12:51pm
Show the loop that you can do.
Jun 11, 2014 at 1:00pm
Last edited on Jun 11, 2014 at 1:00pm
Jun 11, 2014 at 1:08pm
@keskiverto only this
1
2
3
4
for(int i=0; i<100; i++)
{
cout<<i <<" == " << i*i<<endl;
}
and the while loop of it
and
1
2
for(char letter='a'; letter<'a'+26;letter++)
cout<<letter;;


Jun 11, 2014 at 1:09pm
abstractionanon thanks for the link
Topic archived. No new replies allowed.