Hello everybody,
At first i'm creating this thread to ask you guys something relating content from the basic c++ tutorial on this site, i already had a bit of skill relating programming with javascript etc... it always kinda cought my interest so i'm not a total dumbass.
i was at this part of the c++ tutorial that kinda confused me...
http://www.cplusplus.com/doc/tutorial/control.html
If you scroll down you will get to this part:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// number echoer
#include <iostream>
using namespace std;
int main ()
{
unsigned long n;
do {
cout << "Enter number (0 to end): ";
cin >> n;
cout << "You entered: " << n << "\n";
} while (n != 0);
return 0;
}
|
Note that i fully understand the syntax and all of the while loop, but i do not understand the practical use of the "do" function.
I've written my own part of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
int main(){
long number;
while (number != 0)
{
cout << "Give me a number please: ";
cin >> number;
cout << "The number you had given was: " << number << endl;
}
cout << " this line shouldn't be executed " << endl;
// required parameters...
return(0);
}
|
First of all they work both, i made the "long" variable: "number", but i didnt gave it any integer, i just defined the variable wich gives it the value of "NULL" insteed of the numerical "0"
Note that these are different things, NULL wich equals nothing and "0" wich is a numerical value...
Now you might wonder what my problem is... well there aint really a problem except for the fact that the one that wrote this tutorial didnt show any practical use for the "do" while,
Secondly he declared a variable:
unsigned long;
Wtf, unsigned long ???... you mean undefined long ?. I cant remember any topic wich explained the use of unsigned, only by coincidence i came to the conclusion that "long" contains more bytes then "int's" or "double's".
And finally, i didnt get where the "for" loop was good for... The only thing i can see in the for loop is harder syntax and variable's that are defined inside the bracets: "()"
The creator of the tutorial could have prevent a lot of confusion by typing that its only different, a mather of synthax and not of performance.
Now please don't get me wrong, i could have missed some points or overviewed some and thats wy i want you to reply on this thread.
Thank you
Jacob.