[Java] Control syntax notes

Control syntax

Structured theorem

--Sequentially --Branch - if, switch --Repeat - while,for

Branch

//if syntax
int r=new java.util.Random().nextInt(2);
if (r<1){
	System.out.println("This is true by 'if'.");
}else{
	System.out.println("This is false by 'if'.");
}

//switch syntax
int s=new java.util.Random().nextInt(3);
switch(s){
	case 0:
		System.out.println("This is Case.0 by 'switch'.");
		break;
	case 1:
		System.out.println("This is Case.1 by 'switch'.");
		break;
	case 2:
		System.out.println("This is Case.2 by 'switch'.");
		break;
	default:
		System.out.println("This is default by 'switch'.");
}

repetition##

//while syntax
int w=1;
while(w<4){
	System.out.println("Count No."+w+" by 'while'.");
	w++;
}

//do while syntax
int dw=3;
do{
	System.out.println("Count No."+dw+" by 'do while'.");
	dw--;
	System.out.println("Count decrease -1 by 'do while'.");
}while(dw>0);


//for syntax
for(int i=1; i<=3; i++){
	System.out.println("Count No."+i+" by 'for'.");
}

Concept of "interruption of repetition"

-- continue: Continue the loop. --break: Break out of the loop.

//Repeated interruption
for(int i=5; i>=1; i--){
	if(i==3){
		continue;
	}
	if(i==2){
		break;
	}
	System.out.println("Count No."+i+" by 'for/continue(3)/break(2)'.");
}

Reference book

[Introduction to Java 2nd Edition] (https://www.amazon.co.jp/dp/B00MIM1KFC/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1) Pp.098-133.

Recommended Posts

[Java] Control syntax notes
Java control syntax
Java control syntax
java notes
[Java] Summary of control syntax
Notes on signal control in Java
Java Generics (Notes)
[Java] Array notes
Control syntax operator
[Java] Study notes
Java serialization notes
[Java] Stream Collectors notes
Java formatted output [Notes]
Organized memo in the head (Java --Control syntax)
Java NIO 2 review notes
[Java] Basic method notes
Java version control on macOS
[Java] Multi-thread processing --Exclusive control
Try scraping using java [Notes]
[Implementation] Java Process class notes
Java Collections Framework Review Notes
Version control Java with SDKMAN
I touched Scala ~ [Control syntax] ~
Java study # 7 (branch syntax type)
Java version control with jenv
☾ Java / Iterative statement and iterative control statement
Java review ③ (control syntax [if / switch / while / for], conditional expression)
[Java] Object-oriented syntax --class method / argument
[Java] Basic types and instruction notes
[ev3 × Java] Display, sound, LED control
Java
Notes on Android (java) thread processing
Java
Notes on Java path and Package
[ev3 x Java] Single motor control
Java and Swift comparison (2) Basic type / arithmetic expression / control syntax / function definition
Notes on operators using Java ~ String type ~
Output Notes document as XML document in Java
Java syntax changes being considered by Amber
Java version control with jenv on OSX
Java version control using cask + anyenv + jenv
# Java: vol1: [java / JDK version control best practice]
Java installation (Mac, Homebrew, multiple version control)