Go Back   Silkroad Online Gaming Forums > SRA Community Forums > Programmer's Haven

Search Google
Custom Search


Reply
 
Thread Tools Display Modes
Old 06-10-2009   #1 (permalink)
Senior Member
 
kiti's Avatar
 
Join Date: Jun 2008
Location: romania
Posts: 118
My Mood:

Server: 


kiti will become famous soon enough
EXP: 2,153, LVL: 29
EXP: 2,153, LVL: 29 EXP: 2,153, LVL: 29 EXP: 2,153, LVL: 29
LVL up: 53%, 47 EXP Left
LVL up: 53% LVL up: 53% LVL up: 53%
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
IF conditional instruction

With this instruction we can check if a variable has a certain value.

General form:

* - Fixed value

if (variable == value)
* - If no value given

if (variable! = value)
* - If it has a value greater or equal at least:

if (variable> = value)
* - If it has a value less or equal at least:

if (variable <= value)

This instruction may have a second part, which is optional.

if (condition) ( ) else ( )
Between the () "else" is executed only if the condition is false / not take place.

Examples

# include void main () ( int a; cost << "Give value:"; CIN>> a; if (a> = 0) cost << "You entered a positive number"; else cost << "You entered a negative number"; )
There is another possibility:

# include void main () ( int a; cost << "Give value:"; CIN>> a; if (a> 0) cost << "You entered a positive number"; else if (a <0) cost << "You entered a negative number"; else cost << "You entered the void; )
And the "else if" continued ....

# include void main () ( int a, b; cost << "a ="; CIN>> a; cost << "b ="; CIN>> b; if (a> b) cost <

# include void main () ( int a; cost << "Enter a different value of 5; CIN>> a; if (a! = 5) cost << "Correctly"; else cost << "false"; )
Everything is different from 0 is considered true if the condition, and that 0 is false.

Extra
* Operator & & - "si"
- General form

if (conditie1 & conditie2)
- The condition is considered true only if both conditions are true
- Example:
1.

int a = 5, b = 3; if (a == 5 & & b == 3)

cost << "truth";
2.

int a = 5, b = 4; if (a == 5 & & b == 3) cost << "false";
So with this operator we can find out if a variable is located in a desirable:

Or read from the keyboard:

* The operator | | - or
- General form

if (conditie1 | | conditie2)
- The condition is considered true if at least one of the conditions is true
- Examples:
int a = 5; if (a == 5 | | a == 3)

cost << "truth";


int a = 5; if (a == 4 | | a == 3)

cost << "false";
Examples:

 
So much about IF.    
kiti is offline   Reply With Quote
Old 06-11-2009   #2 (permalink)
Senior Member
 
Demon's Avatar
 
Join Date: Jul 2008
Location: Belgium
Posts: 213
My Mood:

Server: 


Demon is on a distinguished road
EXP: 1,824, LVL: 26
EXP: 1,824, LVL: 26 EXP: 1,824, LVL: 26 EXP: 1,824, LVL: 26
LVL up: 24%, 76 EXP Left
LVL up: 24% LVL up: 24% LVL up: 24%
Activity: 1%
Activity: 1% Activity: 1% Activity: 1%
I saw this one in php,
it's really helpfull in a lot of occasions in programming,
nice work (:
__________________

-swSRO: IGN: DemonNuker: lvl 70 hybrid 1:8 spear nuker : active
=>guild: J4mrock
Demon is offline   Reply With Quote
Reply

Latex Maths & Physics Editor ...

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT -5. The time now is 12:48 PM.

Contact Us - Silkroad Online Gaming Forum - Archive