what is repitition structure-counters in c++ ?
I have tried to search this on google , but i couldnt get this .....
Can someone explain it with relevant example ?
Attached thumbnail(s)
repitition structure - counters
repitition structure - counters
|
Oct 24 2016, 11:37 AM, updated 8y ago
Show posts by this member only | Post
#1
|
Senior Member
3,187 posts Joined: Nov 2013 |
|
|
|
|
Oct 24 2016, 11:54 AM
Show posts by this member only | Post
#2
|
Senior Member
4,463 posts Joined: Jan 2003 |
Example (both will display Hello ten times):
CODE for (int i = 0; i < 10; ++i) printf("Hello\n"); or CODE int i = 10; while (i --> 0) printf("Hello\n"); |
|
Oct 24 2016, 11:55 AM
Show posts by this member only | Post
#3
|
Senior Member
3,740 posts Joined: Mar 2009 |
QUOTE(delsoo @ Oct 24 2016, 11:37 AM) what is repitition structure-counters in c++ ? so easy to find internet I have tried to search this on google , but i couldnt get this ..... Can someone explain it with relevant example ? http://www.cs.fsu.edu/~cop3014p/lectures/ch5/index.html but i hate term.. just an increment .. CODE int d=0; while(d<10){ d++; } |
|
Oct 24 2016, 03:45 PM
Show posts by this member only | Post
#4
|
Senior Member
541 posts Joined: Mar 2011 |
guys u r just explaining what it looks like but u dun explain what it replace haha
so without repitition structure if u were to print 1-4 u would do it like this CODE cout << 1 << endl; cout << 2 << endl; cout << 3 << endl; cout << 4 << endl; //notice how they are the same pattern just with different number? but with repetition structure, u introduce a variable to control how many times you want to re-execute the same line of code CODE int i; for(i=1;i<5;i++){ cout << i << endl; //see how now this 1 line of code replaces the 4 lines of code? } now compiler will run this statement 4 times without me writing 4 lines of same code! btw words of advice, don't start asking or searching question online before u try to think the logic behind it, you will never remember it/improve if u keep on getting spoonfed by Internet better yet ask someone to be your mentor in real life This post has been edited by Ryutaro: Oct 24 2016, 03:46 PM |
|
Oct 24 2016, 04:06 PM
Show posts by this member only | Post
#5
|
Senior Member
3,740 posts Joined: Mar 2009 |
QUOTE(Ryutaro @ Oct 24 2016, 03:45 PM) guys u r just explaining what it looks like but u dun explain what it replace haha i teach people by funny example before not term.. because term is to difficult to remember.If you look at lecturer, most will be reusing same term again and again and without knowing how to manipulate it. so without repitition structure if u were to print 1-4 u would do it like this CODE cout << 1 << endl; cout << 2 << endl; cout << 3 << endl; cout << 4 << endl; //notice how they are the same pattern just with different number? but with repetition structure, u introduce a variable to control how many times you want to re-execute the same line of code CODE int i; for(i=1;i<5;i++){ cout << i << endl; //see how now this 1 line of code replaces the 4 lines of code? } now compiler will run this statement 4 times without me writing 4 lines of same code! btw words of advice, don't start asking or searching question online before u try to think the logic behind it, you will never remember it/improve if u keep on getting spoonfed by Internet better yet ask someone to be your mentor in real life |
|
Oct 24 2016, 04:39 PM
Show posts by this member only | Post
#6
|
Senior Member
541 posts Joined: Mar 2011 |
QUOTE(alien3d @ Oct 24 2016, 04:06 PM) i teach people by funny example before not term.. because term is to difficult to remember.If you look at lecturer, most will be reusing same term again and again and without knowing how to manipulate it. i agree term is very difficult to remember.. but those interview always ask u what this term means what that terms means only haha |
|
Oct 24 2016, 08:58 PM
Show posts by this member only | Post
#7
|
Junior Member
635 posts Joined: Jul 2006 |
https://youtu.be/ga_7j72CVlc?t=29
"""You can know the name of that bird in all the languages of the world, but when you're finished, you'll know absolutely nothing whatever about the bird. You'll only know about humans in different places, and what they call the bird. … I learned very early the difference between knowing the name of something and knowing something.""" - Richard Feynman https://en.wikiquote.org/wiki/Richard_Feynm...k.3F_.281988.29 Also, you (one of you anyway, not TS) parsed it incorrectly. It's a chapter on "repetition structures" (????), subchapter "Counter". Very appropriate to C++. (Joke explainer to those new: we used to use "c" as a variable to count things. And the new version of "C" is naturally "C++", which increments C) This post has been edited by angch: Oct 24 2016, 09:00 PM |
|
Oct 24 2016, 09:15 PM
Show posts by this member only | Post
#8
|
Senior Member
3,740 posts Joined: Mar 2009 |
QUOTE(angch @ Oct 24 2016, 08:58 PM) https://youtu.be/ga_7j72CVlc?t=29 lol.. yeah c++.. never think can be a joke. if me no pass correctly... i dam long time no touch c++. only c# and past few month ago try to understand some source c ref.. now i knew what is pointer.. dam long time to understand it and usage. """You can know the name of that bird in all the languages of the world, but when you're finished, you'll know absolutely nothing whatever about the bird. You'll only know about humans in different places, and what they call the bird. … I learned very early the difference between knowing the name of something and knowing something.""" - Richard Feynman https://en.wikiquote.org/wiki/Richard_Feynm...k.3F_.281988.29 Also, you (one of you anyway, not TS) parsed it incorrectly. It's a chapter on "repetition structures" (????), subchapter "Counter". Very appropriate to C++. (Joke explainer to those new: we used to use "c" as a variable to count things. And the new version of "C" is naturally "C++", which increments C) |
Change to: | 0.0143sec
0.07
6 queries
GZIP Disabled
Time is now: 29th March 2024 - 02:14 AM |