It is currently Fri Apr 28, 2017 11:04 am

All times are UTC - 5 hours




 Page 1 of 1 [ 5 posts ] 
Author Message
 Post subject:
PostPosted: Thu Aug 09, 2007 6:46 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
In this VMK I describe how to write a program that can make decisions. I describe the if-else structure and then the AND, OR, NOT, bitwise OR and bitwise AND are described and used.


Offline
 Profile  
 
 Post subject: Re: C++ VMK 2 - Computer Logic
PostPosted: Thu Aug 09, 2007 5:46 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
One thing that I forgot to mention in the video is that there is a short way to achieve the same thing as an if-else statement. Say you want to do something like this:

if(iValue > 10) {
   fValue = 234;
}
else {
   bValue = true;
}



You can write this all in one line using:

(iValue>10 ? fValue = 234 : bValue = true);


the expression before the ? is the first part of the if. Then the part to the left of the : is executed when the if statement suceeds and the part to the right of : is if it fails. Use this condensed version only if the logic is small and simple, otherwise stick with using an if-else.


Last edited by Marek on Thu Oct 22, 2009 5:26 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject:
PostPosted: Mon Oct 19, 2009 3:04 pm 

Joined: Mon Oct 19, 2009 2:39 pm
Posts: 6
ComputerLogic-2.swf seems to be broken. :-(


Offline
 Profile  
 
 Post subject:
PostPosted: Thu Oct 22, 2009 5:42 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
I just downloaded this VMK to test. It plays back correctly on my computer so I suspect that you have a bad copy. Try restarting your computer and download the VMK again.

Also scan your computer for viruses, in the past, members told me they had problems playing back certain SWF files but the problem was fixed when they realized they had a virus.


Offline
 Profile  
 
 Post subject: Re: C++ VMK 2 - Computer Logic
PostPosted: Fri Nov 27, 2009 4:12 pm 

Joined: Wed Jan 07, 2009 9:51 am
Posts: 2
Location: The Netherlands
Marek wrote:
One thing that I forgot to mention in the video is that there is a short way to achieve the same thing as an if-else statement. Say you want to do something like this:

if(iValue > 10) {
   fValue = 234;
}
else {
   bValue = true;
}



You can write this all in one line using:

(iValue>10 ? fValue = 234 : bValue = true);


the expression before the ? is the first part of the if. Then the part to the left of the : is executed when the if statement suceeds and the part to the right of : is if it fails. Use this condensed version only if the logic is small and simple, otherwise stick with using an if-else.

This is named the ternary operator and it is the only operator in C++ that takes three operands.
You probably won't see much of it in source code because many programmers dislike its cryptic syntax.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron