Iterating Over a Block of Expressions in SKILL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] the skill programming language provides many functions for iterating over a block of code with the for loop the while loop and the for each loop being the most common mechanisms for looping will show a quick example of each of these looping structures using an example that we had used in a previous training byte in this example we roll two dice and then have a case function that runs a branch based on the value of the dice a for loop allows us to run a block of code a specific number of times we'll add an argument to our function that will accept an integer and then roll the dice the number of times indicated by the integer using the for loop the for structure requires an iterating variable we'll use X an initial value for X we'll use one and an end a value for X which will use the num rolls integer that is being passed into our function we'll close our for loop with a closed parenthesis and all the code in the for block will be run with each iteration of the loop the loop will set X to the initial value of 1 and automatically increment X by 1 with each iteration until X is greater than our ending value of num roles if we load and run our craps function passing a value of 10 then 10 rolls of the dice are run it is worth noting that the skill for loop is slightly different than other for structures such as in C or Java our control variable can be changed inside the for loop and it will use that new value for that iteration but with the next iteration of the loop the control variable will be set back to its iteration value and incremented by 1 inside our for loop will increment X by 4 and print its value to see that we have changed it but at the end of the loop our control value is reset and our loop will still run num rolls or 10 times notice that if we load and run our function is still loops ten times even though we have incremented X inside of our for loop another way to iterate is with a while loop a while loop will continue to iterate until a specific condition is no longer met let's change our function to iterate until we have rolled 10 Naturals a 7 or an 11 first we'll change our argument name to num naturals instead of numerals and we'll use a while loop instead of a for loop the first expression in a while loop is an expression that must evaluate to a non nil value for the loop to continue running before starting our loop we'll initialize a counter to 0 an increment our counter by 1 each time we roll a natural we'll set our a while loop expression to counter less than num Naturals our while loop will continue to run until this expression is no longer true so we will now continue the roll the dice until we have rolled the number of Naturals that we pass into our function let's load and run our function with a value of 5 and we see that we continue to roll the dice until a natural has come out 5 times another type of looping structure is the for each loop a for each loop will iterate over a list of items until the list of items is exhausted let's change our function to accept a list of dice rolls and iterate over the list of rules once for each role in the list we no longer need our counter and we'll change our argument to be a list of roles will change our while loop to a for each loop and the first argument to the for each loop is a variable that will be local to the for each loop and this variable will be assigned an item of the list dice rolls with each iteration of the loop each item in our dice rolls list will be a list of two integers that represents a dice roll so instead of using random numbers we'll extract the dice values from the two item list if we pass our function a list of 5 dice rolls then our loop will run 5 times once for each item in the list let's load and run our function passing it a list of 5 dice rolls to see our for each loop our loop ran five times but notice that our function now has an inconvenient return value the return value of a for each loop is the list of items that were iterated over and since the for each loop is the last expression in our lap function the let function returns the list and in turn our function returns the list of items that were iterated over let's return the number of items iterated over instead by adding the expression length dice rolls after hour for each loop ends so that our return value is now the number of items that were iterated over in summary the skill programming language provides many functions for iterating over a block of code with the for loop the while loop and the for each loop being the most common mechanisms for looping [Music]
Info
Channel: Cadence Design Systems
Views: 1,056
Rating: undefined out of 5
Keywords: cdns, howto, cadenceEducation, cadenceTraining, demo, tutorial, elearning, webinars, for() loop, while() loop, foreach() loop, SKILL programming language, Allegro PCB Editor, Allegro, PCB Editor
Id: jW7UEF4SQdg
Channel Id: undefined
Length: 5min 22sec (322 seconds)
Published: Mon Apr 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.