In Julia, while loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed. If the condition is false when the while loop is executed first time, then the body of the loop will never be executed.
Syntax :
while expression
statement(s)
end
Here, ‘while‘ is the keyword to start while loop, ‘expression‘ is the condition to be satisfied, and ‘end‘ is the keyword to end the while loop.
Note: A block of code is the set of statements enclosed between the conditional statement and the ‘end‘ statement.
Example 1:
Array = [ "Geeks" , "For" , "Geeks" ]
i = 1
while i < = length(Array)
Object = Array[i]
println( "$Object" )
global i + = 1
end
|
Output:
Example 2:
length = 15
a = 0
b = 1
itr = 0
while itr < length
print (a, ", " )
c = a + b
global a = b
global b = c
global itr + = 1
end
|
Last Updated :
19 Feb, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...