Which one do you prefer?
And what type of loop do you most often use?
My answers: Classes, For.
Which one do you prefer?
And what type of loop do you most often use?
My answers: Classes, For.
-Dean
Are you talking about C++ structs or C structs? Since this is posted on the C++ Board I'll assume C++ structs. There aren't really any differences except in structs everything is treated as public. So, I guess my answer is I use classes more.
I probably use the while loop the most.
Structs are easier, but classes are far more useful.
As for loops, I'd have to say that I use while loops the most, although I like do loops more than most other programmers I talk to. I think they're great for error traps and repeating a program.
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
i really haven't worked much with structs or classes, more with classes though. i like classes better, seem to be more useful. in regards to loops: i like for loops better; in regards to which one i use more, i don't know, depends what i want done, usually while or for.
in C++ structs and classes are pretty much exactly the same (same in functionality, but different in that structs default to public while classes default to private).
I usually use for loops most
Seems like a stupid question but....
classes
while loop
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Didn't know switch was an iterator .Originally posted by adamviper
struct & switch
I prefer none, I use classes in certan circumstances (sp?) and structs in others.
I believe I use while the most.
PS: In this for loop, which value does i have after the iteration ends? 4 or 5?
i = 4 is the last valid value, but i = 5 is what makes i<5 false.
int i;
for(i=0; i<5; i++)
{
...
}
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
I don't know why do you keep asking about which loops are better?
There is no best loop, each loop is deferent from the others, and you use each one according to what you need.
none...
classes and for loops
for loops are far more useful because of their versatility, but thats the only reason I use them more.
Because for is a pretest loop, the last value i has is 4.Originally posted by Magos
PS: In this for loop, which value does i have after the iteration ends? 4 or 5?
i = 4 is the last valid value, but i = 5 is what makes i<5 false.
Code:int i; for(i=0; i<5; i++) { ... }
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
as you start doing more and more programming you end up using..
while loops and classes..
for loops require that you know things in advance.
..the beauty of a binary tree is that there is no need for a loop.. since every node is a mini tree.. you can just hop a long with recursion.
...and i = 5 when that loop ends. i = 4 will be the last value WITHIN the loop
but if you did
for (i = 0; i < 5; i++)
{
....
}
cout << i;
the console would display..
5
You don't need to know any more data for a for loop than you would for a while loop. It's purely a matter of preferance just like struct vs. class. Structs and classes pretty much are the same cept for default access to members.Originally posted by No Man..
for loops require that you know things in advance.
Last edited by Polymorphic OOP; 12-05-2002 at 04:42 AM.