Statement | Syntax |
---|---|
if | If(true) { //execute the code } |
if-else | If(true) { //execute the code-1 } else { //execute the code-2 } |
Nested if | If(true) { //execute the code-1 } Else if(true) { //execute the code-2 } Else { //execute the code-3 } |
Switch/Break/goto | switch (x) { case “A”: break; Case “B”: Goto case”A” } |
Operator | Description | Syntax |
---|---|---|
for | Iterates the statement for ‘n’ number of times. | For(datatype variable;variable<number;variable++) |
foreach | It works similar to for loop but iterates the loop against a value/Object. | For(datatype variable;variable<number;variable++) { //Block of code to execute } |
do | Executes the statement in the loop once before the condition is tested, and, continues only when the condition is satisfied. | do { //Execute block of code }while(variable |
While | Executes the statement in loop only when a condition is satisfied. | While(variable<number) { //Execute block of code } |
continue | It stops the statement execution and allows to check condition again. | for(datatype variable;variable<number;variable++) { //Block of code to execute continue; } |
break | To stop the execution of the statement. | for(datatype variable;variable<number;variable++) { //Block of code to execute break; } |