Sunteți pe pagina 1din 3

if statement: Conditional branching

if (CONDITION) {
Statement
}
CONDITION: The condition in which
statement would be executed (if 1,
execute statement; if 0, skip
statement)

29

for loop
for(INITIALIZATION; CONDITION; INC/DEC){
Statement
}
INITIALIZATION: Initialize the COUNT variable
CONDITION: The condition in which this loop will
continue (if 1, continue; if 0, exit)
INC/DEC: Increment/decrement the COUNT variable
Used when you know how many times the loop should run
An example :
//Using for loops to add numbers 1 - 5
unsigned char sum = 0;
for(int i = 1; i<6; i++)
{ sum += i; }
30

while loop
while(CONDITION){
Statement
}
CONDITION: The condition in which this
loop will continue (if 1, continue; if 0, exit)
Used when you DO NOT know how many
times the loop should run or if the loop
should run infinitely many times (use
while(1)).
31

S-ar putea să vă placă și