Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 repitition structure - counters

views
     
TSdelsoo
post Oct 24 2016, 11:37 AM, updated 8y ago

Look at all my stars!!
*******
Senior Member
3,187 posts

Joined: Nov 2013
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)
Attached Image
dstl1128
post Oct 24 2016, 11:54 AM

Look at all my stars!!
*******
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");


alien3d
post Oct 24 2016, 11:55 AM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(delsoo @ Oct 24 2016, 11:37 AM)
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 ?
*
so easy to find internet
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++;
}

Ryutaro
post Oct 24 2016, 03:45 PM

~ Just a noob programmer ~
****
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
alien3d
post Oct 24 2016, 04:06 PM

Look at all my stars!!
*******
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

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
*
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. icon_rolleyes.gif

Ryutaro
post Oct 24 2016, 04:39 PM

~ Just a noob programmer ~
****
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.  icon_rolleyes.gif
*
i agree term is very difficult to remember.. but those interview always ask u what this term means what that terms means only haha
angch
post Oct 24 2016, 08:58 PM

On my way
****
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
alien3d
post Oct 24 2016, 09:15 PM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(angch @ Oct 24 2016, 08:58 PM)
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)
*
lol.. yeah c++.. never think can be a joke. tongue.gif 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. bangwall.gif

 

Change to:
| Lo-Fi Version
0.0143sec    0.07    6 queries    GZIP Disabled
Time is now: 29th March 2024 - 02:14 AM