1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

はじめてのJulia (5): ループ

Last updated at Posted at 2021-09-06

While

while (条件)と endで挟まれたコードについて、指定した条件が成立する間実行する。

# 1から10まで順に出力する
n = 0
while n < 10
    n += 1
    println(n)
end
n

for

for in (iterable)と endで挟まれたコードについて、iterableの各要素について実行する。

# 1から10まで順に出力する
for i in 1:10
    println(n)
end

for in (iterable)の代わりに、for = (iterable)で始めても良い。 Matlabユーザー救済。

# 1から10まで順に出力する
for i = 1:10
    println(n)
end

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?