![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
hi: for(;;) goto hi;
|
Are there any lessons for idiots?
I mean, I'm not an idiot. But, I just can't keep up with a lot of lessons online. The one at cplusplus.com? Lost me. Anything on Google? Lost me.
I downloaded "Wrox - C++ tutorial.chm" and it's been pretty good to me, but now I'm lost again at arrays. Eventually all lessons seem to assume you know a lot. Is there anything besides a real life book (next plan) anyone can recommend to me, that teaches C++, while..."talking slow"?
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I think you're letting things buffalo you that shouldn't. Probably because of that 'friend' of yours. Suppose you express one or two things that seem incomprehensible to you and let us take a shot at them. There is this about learning: something turns on the lightbulb above someone's head, but it takes a completely different slant to do the same thing for another.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
hi: for(;;) goto hi;
|
This problem existed before the whole Assembly debate, I've had problems getting very far in programming languages since I started.
So far, I've got most of the "basics" down. I can do if, else (if), while, all that stuff. This "for" thing has me a little intimidated, but I might've just not read enough into it. Like I said, arrays have me confused as well. I can declare an array fine, and do some small things with the data inside; I guess I just don't know why I should use it. I also don't get why char variableName[]; would be more effective than string variableName;, but I'm still new. I'm also working on figuring out functions and stuff, since I think it would probably make for cleaner code in large scripts. (One thing I'd like to learn, if possible, is defining functions in one file and being able to use them in your main one) Again, a lot of the tutorials confuse me. As if they're not complicated enough, none of them go in the exact same order. So I might have a small grasp on one subject, until it gets too complicated, then move on to "chapter 3" in another tutorial where they teach something else. This causes me to do less studying than I should, since I want to learn.
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#4 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 655
Rep Power: 4
![]() |
Quote:
Arrays are useful when you want to keep track of a bunch of similar values. In many cases, std::vector in C++ can replace them, though there are still some valid uses. Here is an example: #include <iostream>
int main() {
// Declare an array to hold 5 scores, all of type int.
int scores[5];
// I'm writing this in a format that is easier to comment
// usually 'for' loops would be written all in one line.
//
for(int x = 0; //Set 'x' to be 0. It is only set once.
x < 5; //Iterate while x is less then 5.
x++) //At every iteration, increase the value of 'x' by 1
{
std::cout << "Enter score: ";
//Get input for each successive element in the array
std::cin >> scores[x];
}
std::cout << "You entered the following scores:\n";
//Display the contents of the array.
for(int x = 0; x < 5; x++)
std::cout << scores[x] << std::endl;
}
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
I'll just explain a for loop for you.
In a lot of langauges you can find for loops. As you say you understand while loops I can easily explain how to use them. Here is an example of a for loop: for(int x = 1; x < 11; x++;){
std::cout<< x <<std::endl;
}This code would write the numbers 1 to 10. Firstly you make your new variable: for(int x = 1; x < 11; x++){
std::cout<< x <<std::endl;
}This variable is named x in this loop and it will last until the for loop ends, then it will be discarded. Next, you make a condition, here we have "x < 11" this basically means: While x is less than 11, continue the loop. Then you state what will happen to the variable after each loop, in this case I use x++ which increments the value by one. So this for loop would look like this if it was a while loop: int x = 1;
while (x < 11){
std::cout<< x <<std::endl;
x++; /* increment x by one */
}For loops can differ a lot from that small example but this is the general idea. You can do a lot of other things like leaving parameters out. :banana:
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#6 |
|
hi: for(;;) goto hi;
|
Aha. So a "for" is (basically) initializing a variable combined with a while loop of some sort.
I'm creating my own examples (by memory, without looking at what you gave me) to see if I can get it right on my own. Hitting some speed bumps, but the whole for thing is clear now. I guess the next thing I need to tackle is pointers, which really threw me off.
__________________
How do you play Religious Roulette? Stand around in a circle and blaspheme till someone gets struck by lightning. |
|
|
|
|
|
#7 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3
![]() |
A for loops works like this (one line pseudo-code definition):
for(Initialization; Condition; Update)
{
// ...
}Initialization;
while(Condition)
{
// ...
Update;
} |
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
peaceofpi, I wouldn't even try and touch pointers until you at least have a fairly good grasp of the rest of the basic stuff you've mentioned, they throw a lot of people off at first, try to tackle them with a clear head, without wondering why the heck the example is doing that thing with that arrayjamawhatjimacallit!
But in all seriousness I think people will agree with me on that, get a good foundation, then expand!
__________________
www.heldtogether.co.uk |
|
|
|
|
|
#9 |
|
Professional Programmer
|
But when you do look at pointers, head over to http://daweidesigns.com and read up about pointers there.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#10 |
|
Newbie
|
When your stuck on something, dont just skip it and keep going, and going, stop, backup and read it again, almost always works for me.
Its easy to say...oh that doesn't look to importent and skip it "For now", but thats what gets you in trouble >_<, i did alot of that when i first started, Then i got smart and just read everything multiple times. Anyways good luck =P |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|