Loop statement

Before

Programming beginners are learning by themselves. Since it is in a state of groping, there may be a lot of things to do.

Purpose

As I proceeded with learning, when I expanded the learning language, I thought that even if I had done it in the past, the grammar would be confused and I would often search again, so it is rudimentary. I decided to leave it as my own memo even if it was something.

Loop statement

Java

for statement

for (Preparation of variables; Repeat condition; Update of variables)

qiita.java


for(int i = 0; i < 5; i++) {
  System.out.println(i); //processing
}
=>
1
2
3
4
5
Extended for statement

for (Preparation of type variable: Array to be processed)

qiita.java


String[] team = {"Brave", "Warrior"} 

for(String member : team) {
  System.out.println(member); //processing
}
=>
Brave
Warrior

Ruby

for statement

for variable in number of iterations

qiita.rb


for i in 1..5
  puts i
end
=>
1
2
3
4
5
times statement

Number of times .times do

qiita.rb


5.times do 
  puts "Repeat"
end
=>
Repeat
Repeat
Repeat
Repeat
Repeat

Recommended Posts

Loop statement
switch statement
Loop processing
if statement
StackOverflowError (infinite loop)
Java for statement
Java switch statement
About a double loop that puts a For statement inside a For statement
How to loop Java Map (for Each / extended for statement)
Java SE Bronze Exam Number: 1Z0-818 (Loop Statement) (October 2020)