Main Menu


Sponsored Links

  


  
  
Web Cartoon Maker: a Fun Way to Learn C++ Contents Previous Next

Conditional Execution

In order to make advanced cartoons, we almost always need the ability to check certain conditions and change the behavior of the program accordingly. Conditional statements give us this ability. The simplest form is the if statement:

if ( iX < 0 )

{

Max.Wink ();

}

The expression in parentheses is called the condition. If it is true, then the statements in brackets get executed. If the condition is not true, nothing happens.

The condition can contain any of the comparison operators:

  • x == y // x equals y

  • x != y // x is not equal to y

  • x > y // x is greater than y

  • x < y // x is less than y

  • x >= y // x is greater than or equal to y

  • x <= y // x is less than or equal to y

Although these operations are probably familiar to you, the syntax C++ uses is a little different from mathematical symbols like =, 6= and ≤. A common error is to use a single = instead of a double ==. Remember that = is the assignment operator, and == is a comparison operator. Also, there is no such thing as =< or =>. The two sides of a condition operator have to be the same type. You can only compare ints to ints, doubles to doubles and so on. In classic C++ you cannot compare strings, but it is possible in WCM C++ because of its string extensions.


Contents Previous Next
  
News

New Tales Animator Video by Alan Sturgess

Alan Sturgess shared an excellent video he made using Tales Animator! You can still download Tales Animator here. Unfortunately it is only available for Wi

...

Simple Online Character Designer

There is a prototype of simple online character designer available HERE. It is only a prototype, it does not contain many pieces yet but it can already generat

...

Book is updated

Now our book "Web Cartoon Maker: A Fun Way to Learn C++" is fully in synch with WCM 1.5! It is available for download and online reading HERE.

...

Web Cartoon Maker 1.5 is here!

Web Cartoon Maker 1.5 is finally here! You can download it HERE! Here is what was updated in version 1.5: Web Cartoon Maker Desktop Edition is now fully standal

...

read more news...


Poll