Some very specific questions about C++ writing.

Hello I'm a real newbie on C++.

I just started to learn it by my self and it really draws me in... I'm using a book: 'Beginning Programming with C Plus Plus for Dummies Ebook'.

My question is about the semicolons:
Why sometimes I use ";" and sometimes I don't, When do I have to and when do I not?
I can't get used to it, I'm sure it maintains consistency, but i cant get to learn it, so i need some tips with that. Here is a piece of a code for example:
while (nValue <= nTarget) <------- where is the ";"
cout << nAccumulator << " * "
<< nValue << " equals ";
Thank you very much for reading it,
And another big THANK YOU for trying to help a newb like me.
Hello, Shalito. Welcome to cplusplus forums :)
When posting code, please use code tags, which can be found to the right of the text box (the <> button.)

Semicolons are used at the end of every statement.

Control structures, like while loops, for loops, and if/else are not considered 'statements' in the same sense. Think of them as structures who's bodies are enclosed in brackets.

int x; //one complete statement, needs a semicolon.
cout << "Input X: " << endl; //one complete statement, needs a semicolon.

if(x < 0) //control structure, no semicolon, but follow with a bracket
{ //open control structure
    cout << "X is negative." << endl; //complete statement, use a semicolon.
} //closes control structure
else //control structure, no semicolon
{ //open control structure
    cout << "X is positive." << endl; //complete statement
} //closes control structure 

Hope that cleared it up a little bit for you.
Thank you very much Thumper! It really helped me!
Topic archived. No new replies allowed.