Loops & Conditional Statements
Conditional Statements
if statement
if( condition ) {
statement;
} else{
statement
}switch statement
switch(argument value) { // Not a conditional expression, but an argument value!
// -> Only data types that can be promoted to int can be used as the argument value!
// ex) Integer types (byte, short, int), character type (char)
case condition value 1: // => It's a colon(:), not a semicolon(;)!!!!!
statement; // -> Statement to be executed when the conditional expression result matches the condition value
break; // => break must be included for proper operation
case condition value 2:
statement;
break;
case condition value 3:
statement;
break;
case condition value 4:
statement;
break;
Default: // => default is for exiting when none of the conditions match!
statement;Loops
for loop
Nested for loop
Enhanced for loop
while loop
do ~ while loop
break statement
continue statement
Difference between break and continue statements
The return statement terminates the function itself
Last updated