Conditionals & Loops
Description of conditional statements and loops
Last updated
if (condition) {
code to be executed if condition is true;
}
else {
if the above condition is false, then else is called;
}if (@rax == 55) {
printf("rax is equal to %llx\n", @rax);
}
else {
printf("rax is not equal to 0x55, it is equal to %llx\n", @rax);
}if (condition) {
code to be executed if condition is true;
}
elsif (condition) {
code to be executed if elsif condition is true;
}
else {
if none of the above conditions are true, then else is called;
}if (@rax == 55) {
printf("rax is equal to 0x55\n");
}
elsif (@rax == 66) {
printf("rax is equal to 0x66\n");
}
elsif (@rax == 77) {
printf("rax is equal to 0x77\n");
}
else {
printf("rax is not equal to 0x55, 0x66, 0x77. It is equal to %llx\n", @rax);
}for (initial value; condition; incrementation or decrementation) {
code to be executed in loop;
}for (i = 10; i != 0; i--) {
printf("%d\n", i);
}for (i = 0; i < 10 ; i++) {
for (j = 0; j < 10; j++) {
printf("%d, %d\n", i, j);
}
}while (condition) {
code to be executed if while condition is true;
}x = 55;
while (x) {
printf("x = %x\n", x);
x = x - 1;
}do {
code to be executed at least one time and continues,
if while condition is true;
}
while (condition); x = 55;
do {
printf("x = %x\n", x);
x = x - 1;
} while (x);