| | |
if then statement
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
c and c++ does not use the "then" statement as some other languages do. The next statement or block following the if statement is executed when the if statement is true. Notice the use of the double '=' symbol which is the logical equal. A single '=' means assignment. Lots of people get tripped up on those differences -- even some old timers like me :o
C++ Syntax (Toggle Plain Text)
if( g == 3282) { // true condition g = k; } else { // false statement }
>how do u write this if then statment but in c++ if g=3282 then g=k;
Don't you have a book? Learning a language is extremely difficult without a proper reference available.
>to bad there wasnt a then like there is an else in c++
Why? "then" is typically used as a language defined parsing helper for the compiler, like the parentheses in C++. When the parser finds "if", it processes a conditional test until it finds the corresponding "then". Compare:
It's pretty obvious that this framework is already in place in C++; it just doesn't use the same tokens.
Now, an interesting tidbit that's largely unrelated is that "then" isn't always used like that. In a stack based language like FORTH, the parsing trick isn't needed, and "then" is used as a conditional terminator (what other languages use "endif" for):
Don't you have a book? Learning a language is extremely difficult without a proper reference available.
>to bad there wasnt a then like there is an else in c++
Why? "then" is typically used as a language defined parsing helper for the compiler, like the parentheses in C++. When the parser finds "if", it processes a conditional test until it finds the corresponding "then". Compare:
C++ Syntax (Toggle Plain Text)
if a = b then <statements> endif
C++ Syntax (Toggle Plain Text)
if ( a == b ) { <statements> }
Now, an interesting tidbit that's largely unrelated is that "then" isn't always used like that. In a stack based language like FORTH, the parsing trick isn't needed, and "then" is used as a conditional terminator (what other languages use "endif" for):
C++ Syntax (Toggle Plain Text)
a b = if <statements> then
New members chased away this month: 4
>whoa narue thats cool that there is an endif
Well, not in C++. But you can fake it with macros if you're a sadist:
But, don't do that. You won't be able to show your code to very many people before they lynch you.
Well, not in C++. But you can fake it with macros if you're a sadist:
C++ Syntax (Toggle Plain Text)
#define then { #define endif } if ( a == b ) then <statements> endif
New members chased away this month: 4
•
•
•
•
Originally Posted by Narue
But, don't do that. You won't be able to show your code to very many people before they lynch you.
•
•
Join Date: Mar 2006
Posts: 163
Reputation:
Solved Threads: 2
thats amasing so macros are suplimentations from other codes, but instead i allso agree that thats stupid. if u want to creat a program in another launge then u should just supliment that santax into an other programs santax instead of using macros, and ok i thought i got it but now im not shure um does this soud corect anyways though?
the { }brackets are sublimented for the then, so ?
the { }brackets are sublimented for the then, so
C++ Syntax (Toggle Plain Text)
(if a==b) /*then*/{a=2}
•
•
Join Date: Mar 2006
Posts: 163
Reputation:
Solved Threads: 2
also i tried that here but it didnt work
here r the errors
C:\Dev-Cpp\Untitled2.cpp In function `int main(int, char**)':
37 C:\Dev-Cpp\Untitled2.cpp expected `;' before '}' token
here r the errors
C++ Syntax (Toggle Plain Text)
if( g == 3282) {g = k;} else {g=0}
C:\Dev-Cpp\Untitled2.cpp In function `int main(int, char**)':
37 C:\Dev-Cpp\Untitled2.cpp expected `;' before '}' token
here r the errors
![]() |
Similar Threads
- missing return statement (Java)
- MySQL LIKE statement (MySQL)
- loop in main function to an "if" statement (C++)
- Switch Case Statement (Java)
- run sql statement in asp (ASP)
- switch/case statement (C++)
- change statement (JSP)
- Reading MSWord Document through an ASP Statement (ASP)
Other Threads in the C++ Forum
- Previous Thread: radix sort using queue and linked list
- Next Thread: C++ Compile Error's
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






