CT GunZ Server
Would you like to react to this message? Create an account in a few clicks or log in to continue.
CT GunZ Server

CT GunZ EN-Forums
 
HomeHome  PortalPortal  Latest imagesLatest images  SearchSearch  RegisterRegister  Ger Forums  GunZ Register  Server  VOTE please  Be Donator  Download CTGunZ  Log inLog in  

 

 Coding TuT 9

Go down 
4 posters
AuthorMessage
bossxd
BANNED
BANNED
bossxd


Male

Number of posts : 21
Location : usa
Points : 64
Character : Noname
GunZ Exp (nub/pro) :
Coding TuT 9 Left_bar_bleue0 / 1000 / 100Coding TuT 9 Right_bar_bleue

Registration date : 2009-04-12
Reputation : 0


Coding TuT 9 Empty
PostSubject: Coding TuT 9   Coding TuT 9 EmptyTue Apr 14, 2009 10:44 am

Data handling and conditionals

Operators, if, switch and loops.

Operators
Operator Meaning Example
= Assign a value int variable = value;
== Equal to? (2 == 3) returns false
!= Not equal to? (2 != 3) returns true
< Less than? (2 < 3) returns true
> Greater than? (2 > 3) returns false
= 2) returns true
&& AND ((2 != 3) && (3 != 3)) returns false
|| OR ((2 != 3) || (3 != 3)) returns true
if
All useful programs will need to use conditional statements - code that is only executed IF a condition is met. Conditionals allow your code to make decisions based on variable values. For example, you can output one string if your bank balance calculation comes out negative and another when you are in credit.

float balance = 74.52;
// Do some calculations here
if (balance < 0) {
printf("You are overdrawn by �%.2f", balance);
}
if (balance > 0) {
printf("Your balance is �%.2f", balance);
}
Logical operators
When you need to combine two comparisons in one decision, you can use two separate conditions, one inside the other:

float balance = -74.52;
float overdraft = -50;
// Do some calculations here
if(balance < 0) {
if(balance > overdraft) {
printf("You have exceeded your overdraft limit by �%.2f", balance - overdraft);
}
}
Be careful when nesting blocks in this way. A good editor will highlight matching brackets but you must make sure that any one block starts and ends where you expect it. Indenting blocks works when you are consistent with the indent - one tag per bracket.

These can be combined into one statement using AND

if((balance < 0) && (balance > overdraft)) { }
switch
When you have a series of conditional statements all based on a single variable, you can use a switch statement to improve the speed and readability of the code.

switch(variable) {
case constant1 : {
// statement block 1
break;
}
case constant2 : {
// statement block 2
break;
}
default : {
// statements
break;
}
}
If the value of variable matches the value of constant1, statement block 1 will be executed. The break keyword causes execution to drop out of the switch statement to execute the rest of the program. If the value of variable does not match either constant1 or constant2, the default statement block will be executed. The default block is optional.

Loops
Statements executed as a result of an if statement can be repeated using while loops. For as long as the conditional statement remains true, the statement block will execute. At least one statement within the block must provide a way of ending the loop by making the conditional return false:

int end = 10;
int start = 0; while(start < end) {
// statement block
start++;
}
++ is the increment operator - start++ increases the value of start by one each time the statement is executed. Therefore, the statement block will execute ten times with values of start increasing from the initial 0 to 9. Once start is incremented to ten, the conditional statement start < end returns false and the program continues without executing the loop. There is also a decrement operator -- that can be used to make a loop count backwards.

Where the start and end point of the loop are already known or fixed, a for() {} loop is more efficient:

for(int count=0;count
Back to top Go down
Torrentspy
Administrator
Administrator
Torrentspy


Male

Number of posts : 843
Location : hidding
Points : 574
Character : Torrent_Spy
GunZ Exp (nub/pro) :
Coding TuT 9 Left_bar_bleue90 / 10090 / 100Coding TuT 9 Right_bar_bleue

Registration date : 2009-01-15
Reputation : -2


Coding TuT 9 Empty
PostSubject: Re: Coding TuT 9   Coding TuT 9 EmptyTue Apr 14, 2009 1:25 pm

what does this code do?
Back to top Go down
Snake
Retired Staff
Snake


Male

Number of posts : 3572
Age : 31
Location : UK
Points : 3473
Character : Coding TuT 9 Snake11copy-1
GunZ Exp (nub/pro) :
Coding TuT 9 Left_bar_bleue99 / 10099 / 100Coding TuT 9 Right_bar_bleue

Registration date : 2009-02-02
Reputation : 27


Coding TuT 9 Empty
PostSubject: Re: Coding TuT 9   Coding TuT 9 EmptyTue Apr 14, 2009 2:52 pm

O.o All these TUT's mean nothing to me lol, i'm just say goodjob... to encourage you to keep it up Very Happy
Back to top Go down
Tittenfee
Retired Staff
Tittenfee


Warnings : 2.99
Male

Number of posts : 2522
Age : 30
Location : Austria, Vienna
Points : 2583
Character : Tittenfee, _NPC_
GunZ Exp (nub/pro) :
Coding TuT 9 Left_bar_bleue69 / 10069 / 100Coding TuT 9 Right_bar_bleue

Registration date : 2009-01-22
Reputation : 22


Coding TuT 9 Empty
PostSubject: Re: Coding TuT 9   Coding TuT 9 EmptyWed Apr 15, 2009 9:44 am

u cant teach us coding just by tuts rofl... its complicated and hard to understand
Back to top Go down
Sponsored content





Coding TuT 9 Empty
PostSubject: Re: Coding TuT 9   Coding TuT 9 Empty

Back to top Go down
 
Coding TuT 9
Back to top 
Page 1 of 1
 Similar topics
-
» Coding TuT 11
» Coding TuT 12
» Coding tut
» Coding TuT 2
» Coding TuT 3

Permissions in this forum:You cannot reply to topics in this forum
CT GunZ Server :: Basket-
Jump to: