How to create Fibonacci Series

Hi All,

I am trying to create a Fibonacci series but not sure how to use the looping condition and how to assign and save that series in array variable. Please advise

Thanks and Regards,
Prateek

2 Likes

What have you done so far? Did you try iterating with Do While?

1 Like

Hi @Prateek0527,

Like Vaidya mentioned, try using a Do while loop and within the loop you can assign the array variable with the temp result. Since you want to append to the array, you could use an assign to the resulting array with the Concat method and then convert ToArray like this:
resultArr = resultArr.Concat ({tempResult}).ToArray()

Regards,
PD

1 Like

I also wanted to add that, you might like to go through the Foundations Course in the Academy. You will find it beneficial.

Happy Automation!

Regards,
PD

2 Likes

Hi PD,

Thanks for the information . I had started the foundation course and had just completed the various types of loops in workflows (Lesson 2) , so just wanted to try whether i can create the series with this knowledge . Like Vaidya said , I thought of doWhile loop but just not able to understand how to approach it.

1 Like

Hi @Prateek0527,
Find this solution Flowchart.xaml (19.3 KB)
If you have any doubt . Let me know.

Regards,
naveen

1 Like

use a collection (like a list), so you can add always an new item of the fibonnaci serie.
You can use a while loop with the length of the wanted serie as stop criterium

Kr,

Tom

Hi @Naveen_tg ,

Thanks for the Solution. I haven’t gone through List topic so some syntax were new to me. I tried creating through sequence and also got the series . But in the after the final number , it is displaying 0 at the end of the series . Please take a look and let me know where i did wrong.

Thanks and Main.xaml (11.1 KB)
Regards,
Prateek

hi @Prateek0527,

Change ur do while condition to Num1 <=fibonacciLen

U were getting 0 bcz u were performing only it array(length-1))
so the last value of array was default 0

Regards,
naveen

Hi @Naveen_tg,

Assuming that array position starts from 0 and i have initialized the array size i.e arrNumber= new Integer( fibonacciLen){} where for example i have taken fibonaaciLen = 11 .Thus the the length of array should also be 11 i.e. from arrNumber[0] - arrNumber[10].

Now i have already initialized arrNumber[0]=0 &arrNumber[1]=1 and starting from arrNumber[2] . In dowhile loop after arrNumber[10] is stored , condition 11<11 comes , which is not true , thus it comes out of the loop .

Then why is it showing the value of arrNumber[11]=0 when clearly i had defined the size/length till arrNumber[10] . Also when i am displaying the length of array at the end , it comes as 12 which is also confusing as i had earlier initialized it with 11.

Kindly let me know if my thought process is correct or if i am going in a totally wrong direction. :slight_smile:

Thanks and Regards,
Prateek

hi @Prateek0527,
arrNumber = new Integer(11){} this will set your array length upto index 11,ie, 12 elements!
Thats y that default the value of arrNumber[11] = 0

Hope this helps!

Regards,
naveen

Hi @Naveen_tg,

Thanks for this information and clearing the doubt . :slight_smile:

Thanks and Regards,
Prateek

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.