note06
◆ while ~ end statement
i = 0 #i initialization
while i <= 10
println(i)
global i += 1 #Global variable
end
◆ for ~ end statement(=When using equal)
for i = 1:10
println(i)
end
◆ for ~ end statement(When using in)
list = [1, 5, 10]
for i in list
println(i)
end
-In Julia, ** whilte ~ end ** statement and ** for ~ end ** statement can be used for loop processing. Iterative processing is executed in the part between whilte and for until end. -The major difference from Python is that there is ** end **. -Variables used inside blocks such as while and for cannot be used outside blocks because they are local variables.
In the 4th line, ** global ** is added to the variable i.
If you want to use the variable i not only inside the loop processing (between while and end) but also outside, add global like this. Also, the value cannot be changed inside the loop processing unless global is added.
On the contrary, if you do not change the variable i, you do not need to add global. Only read is possible inside the loop process.
The variable i is repeated from 1 to 10. Please note that Julia will execute up to the last 10 of the slices ** 1: 10 **. (Python only runs 1-9)
By setting a list type variable in the list part of the second line, you can also loop with the in operator.
Julia Quick Look Note [01] How to use variables and constants Julia Quick Look Note [02] Arithmetic Expressions, Operators [Julia Quick Note [03] Complex Numbers] (https://qiita.com/ttabata/items/225c77a4d71fafc3e482) Julia Quick Look Note [04] Regular Expression [Julia quick note [05] if statement] (https://qiita.com/ttabata/items/4f0bcff1e32f60402dfb) [Julia fast-drawing note [06] loop processing] (https://qiita.com/ttabata/items/2a53825101b0b75fb589) [Julia Quick Note [07] try, catch, finally] (https://qiita.com/ttabata/items/1d6fe990526c99b65b5f)
(* We will continue to increase the content)
: paperclip: Julia --Official page https://julialang.org/
: paperclip: Julia --Japanese official document https://julia-doc-ja.readthedocs.io/ja/latest/index.html
: paperclip: First time Julia and installation (Windows & Linux) https://qiita.com/ttlabo/items/b05bb43d06239f968035
:paperclip: Julia - Mathematics https://docs.julialang.org/en/v1/base/math/
If you have any opinions or corrections, please let us know.
Recommended Posts