Skip to content

Instantly share code, notes, and snippets.

@shah-smit
Last active May 2, 2017 05:38
Show Gist options
  • Save shah-smit/af2c59238e0caa553a22b574c9c9d778 to your computer and use it in GitHub Desktop.
Save shah-smit/af2c59238e0caa553a22b574c9c9d778 to your computer and use it in GitHub Desktop.
Format of Statements, Loops and Methods and Classes In java

Format

Statement

IF STATEMENT

if(<condition>) <body>

ternary operator ? :

<condition> ? <true> : <false>
example:
boolean found = true;
int n = found ? 10 : 20; //output 10

Loop

FOR LOOP

for(<initialisation>,<guard or condition>, <increment or decrement expression>) <body>

syntactically correct loop: for(;;);

Label For Loop

                up:
		for(int i=0; i<10;i++){
			low:
			for(int j=0;j<5;j++)
			{
				if(i == 5 && j ==4){
					break up;
				}
				if(j==1) continue;
				if(i==4) break low;
				System.out.println(i+" "+j);
			}
		}

WHILE LOOP

declaration and initiatialisation
while(<condition>) {
<body>
<increment or decrement expression> }
declaration and initiatialisation
do { <body> }
while(<condition>) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment