& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
Understanding loops.
Type:
Tutorial
Length:
6 min.
Transcript
00:03
Loop code blocks control how many times the block body is run.
00:08
These are called loops since the body is repeated multiple times,
00:12
reminding us of loops of rope, a
00:15
pass through the loop is called an iteration.
00:19
The simplest repeat block runs the code in its body the specified number of times.
00:25
For example,
00:26
here, the block will print informed design three times.
00:33
Additionally,
00:34
you can add a math block to calculate the number of times to iterate through the loop.
00:40
Here.
00:40
A parameter is used to calculate a value
00:43
by subtracting four from the wall height value.
00:47
When the loop is run,
00:49
the block will print inform design four times
00:53
calculated from the wall height value of eight minus four,
00:58
updating the wall height prompts the loop block to run
01:02
and recalculate the number of loops to print. Inform design
01:07
the repeat while loop block will iterate over the block.
01:11
As long as the condition is true
01:14
here, a variable called I is initially set to zero
01:19
and the loop is evaluated to run while I is less than the wall height,
01:24
the due portion of the block is set to print the value of I. When the code block is run.
01:30
This is done by using the print block combined with a create text with block
01:36
and then adding a text block combined with another block to get the value of I.
01:41
When the form is used to test the code block,
01:44
an infinite loop error is displayed
01:47
informing us that the wild condition never terminated to end the loop
01:52
to resolve the error.
01:54
A change by block is added to increment the I variable
01:58
by a value of one each time the loop is repeated
02:02
using the form to test the code again.
02:04
Now demonstrates that the loop is advancing the value of I by one for each iteration.
02:11
But only while I is less than the parameter value,
02:16
you can use the drop down list to convert a repeat while loop to a repeat
02:21
until loop
02:23
repeat until loops are similar to wild loops.
02:27
But they only repeat until the condition is true. And then they stop looping
02:34
the count with block iterates a variable from one value to
02:37
another value by a specified increment amount looping once for each step
02:43
here, the block prints the numbers between one and 12 incrementing by three.
02:49
In this example, the increment is set to three. So I advances from 10 to 13
02:56
and therefore never reaches 12. So 10 is the last number printed.
03:01
The four each block iterates over the values in a list.
03:05
So rather than stating loop X, many times
03:09
the four, each block states loop through every item in the set of values.
03:15
In this example,
03:16
each value is displayed in the print pop up window
03:20
here. A four, each block is placed in the canvas.
03:24
Then a variable called material is created
03:27
and the four, each block is set to use this variable as the iterator.
03:33
Next, the parameter is selected to use as the list to iterate or loop over
03:39
attaching the block straight from the parameters
03:41
library is not allowed because the four,
03:44
each block expects a list
03:46
and not just a value
03:48
to resolve this. The parameter function is changed from the singular
03:53
value
03:54
to the plural
03:56
values, which is a list
03:59
to display the list of values.
04:01
The print block is added from the text code blocks library
04:05
and then the material variable is added to it
04:09
to run the code and generate the print pop up containing the list of materials.
04:14
The update button is pressed
04:17
most loops run until a terminating condition is reached
04:21
or until all values have been looped through.
04:24
But in some circumstances,
04:26
adding a loop termination block is desirable
04:30
here. A block is added to exit or break out of the loop.
04:34
If the list encounters high impact gypsum,
04:38
the print pop up displays every item in the list
04:41
that was encountered up until high impact was reached.
04:44
And the loop was exited.
04:47
The termination block can be changed from breakout to continue with next iteration
04:53
in order to simply skip printing high impact gypsum.
04:58
In summary,
04:59
loop blocks provide a way for your logic to efficiently run multiple times
05:05
repeat loops allow a block to loop while or until a condition is met.
05:11
The count with block loops from one number to another by a specified increment.
05:16
The four each loop iterates through values in a list,
05:20
loop termination blocks,
05:22
exit the block or skip an iteration when a condition is met.
Video transcript
00:03
Loop code blocks control how many times the block body is run.
00:08
These are called loops since the body is repeated multiple times,
00:12
reminding us of loops of rope, a
00:15
pass through the loop is called an iteration.
00:19
The simplest repeat block runs the code in its body the specified number of times.
00:25
For example,
00:26
here, the block will print informed design three times.
00:33
Additionally,
00:34
you can add a math block to calculate the number of times to iterate through the loop.
00:40
Here.
00:40
A parameter is used to calculate a value
00:43
by subtracting four from the wall height value.
00:47
When the loop is run,
00:49
the block will print inform design four times
00:53
calculated from the wall height value of eight minus four,
00:58
updating the wall height prompts the loop block to run
01:02
and recalculate the number of loops to print. Inform design
01:07
the repeat while loop block will iterate over the block.
01:11
As long as the condition is true
01:14
here, a variable called I is initially set to zero
01:19
and the loop is evaluated to run while I is less than the wall height,
01:24
the due portion of the block is set to print the value of I. When the code block is run.
01:30
This is done by using the print block combined with a create text with block
01:36
and then adding a text block combined with another block to get the value of I.
01:41
When the form is used to test the code block,
01:44
an infinite loop error is displayed
01:47
informing us that the wild condition never terminated to end the loop
01:52
to resolve the error.
01:54
A change by block is added to increment the I variable
01:58
by a value of one each time the loop is repeated
02:02
using the form to test the code again.
02:04
Now demonstrates that the loop is advancing the value of I by one for each iteration.
02:11
But only while I is less than the parameter value,
02:16
you can use the drop down list to convert a repeat while loop to a repeat
02:21
until loop
02:23
repeat until loops are similar to wild loops.
02:27
But they only repeat until the condition is true. And then they stop looping
02:34
the count with block iterates a variable from one value to
02:37
another value by a specified increment amount looping once for each step
02:43
here, the block prints the numbers between one and 12 incrementing by three.
02:49
In this example, the increment is set to three. So I advances from 10 to 13
02:56
and therefore never reaches 12. So 10 is the last number printed.
03:01
The four each block iterates over the values in a list.
03:05
So rather than stating loop X, many times
03:09
the four, each block states loop through every item in the set of values.
03:15
In this example,
03:16
each value is displayed in the print pop up window
03:20
here. A four, each block is placed in the canvas.
03:24
Then a variable called material is created
03:27
and the four, each block is set to use this variable as the iterator.
03:33
Next, the parameter is selected to use as the list to iterate or loop over
03:39
attaching the block straight from the parameters
03:41
library is not allowed because the four,
03:44
each block expects a list
03:46
and not just a value
03:48
to resolve this. The parameter function is changed from the singular
03:53
value
03:54
to the plural
03:56
values, which is a list
03:59
to display the list of values.
04:01
The print block is added from the text code blocks library
04:05
and then the material variable is added to it
04:09
to run the code and generate the print pop up containing the list of materials.
04:14
The update button is pressed
04:17
most loops run until a terminating condition is reached
04:21
or until all values have been looped through.
04:24
But in some circumstances,
04:26
adding a loop termination block is desirable
04:30
here. A block is added to exit or break out of the loop.
04:34
If the list encounters high impact gypsum,
04:38
the print pop up displays every item in the list
04:41
that was encountered up until high impact was reached.
04:44
And the loop was exited.
04:47
The termination block can be changed from breakout to continue with next iteration
04:53
in order to simply skip printing high impact gypsum.
04:58
In summary,
04:59
loop blocks provide a way for your logic to efficiently run multiple times
05:05
repeat loops allow a block to loop while or until a condition is met.
05:11
The count with block loops from one number to another by a specified increment.
05:16
The four each loop iterates through values in a list,
05:20
loop termination blocks,
05:22
exit the block or skip an iteration when a condition is met.
Loop code blocks control how many times the block body is run.
These are called loops since the body is repeated multiple times, reminding us of loops of rope.
A pass through the loop is called an iteration.
The simplest repeat block runs the code in its body, the specified number of times.
For example, here the block will print Informed Design three times.
Additionally, you can add a math block to calculate the number of times to iterate through the loop.
Here, a parameter is used to calculate a value by subtracting four from the wall height value.
When the loop is run, the block will print Informed Design four times calculated from the wall height value of eight minus four.
Updating the wall height prompts the loop block to run and recalculate the number of loops to print Informed Design.
The repeat while loop block will iterate over the block as long as the condition is true.
Here, a variable called I is initially set to zero, and the loop is evaluated to run while I is less than the wall height.
The due portion of the block is set to print the value of I when the code block is run.
This is done by using the print block combined with a create text with block. And then adding a text block combined with another block to get the value of I.
When the form is used to test the code block, an infinite loop error is displayed informing us that the while condition never terminated to end the loop. To resolve the error, a change by block is added to increment the I variable by a value of one each time the loop is repeated.
Using the form to test the code again, Now demonstrates that the loop is advancing the value of I by one for each iteration, but only while I is less than the parameter value.
You can use the drop down list to convert a repeat while loop to a repeat until loop.
Repeat until loops are similar to while loops, but they only repeat until the condition is true and then they stop looping.
The count with block iterates a variable from one value to another value by a specified increment amount. Looping once for each step.
Here, the block prints the numbers between one and twelve, incrementing by three. In this example, the increment is set to three. So I advances from ten to thirteen, and therefore never reaches twelve. So ten is the last number printed.
The four each block iterates over the values in a list. So rather than stating loop x many times, the four each block states loop through every item in the set of values.
In this example, each value is displayed in the print pop up window.
Here, a four each block is placed in the canvas.
Then a variable called material is created, and the for each block is set to use this variable as the iterator.
Next, the parameter is selected to use as the list to iterate or loop over.
Attaching the block straight from the parameters library is not allowed because the foreach block expects a list and not just a value.
To resolve this, the parameter function is changed from the singular value to the plural.
Values, which is a list.
To display the list of values, the print block is added from the text code blocks library, and then the material variable is added to it.
To run the code and generate the print pop up containing the list of materials, The update button is pressed.
Most loops run until a terminating condition is reached, or until all values have been looped through. But in some circumstances, adding a loop termination block is desirable.
Here, a block is added to exit or break out of the loop if the list encounters high impact gypsum.
The print pop up displays every item in the list that was encountered up until high impact was reached, and the loop was exited.
The termination block can be changed from breakout to continue with next iteration in order to simply skip printing high impact gypsum.
In summary, loop blocks provide a way for your logic to efficiently run multiple times.
Repeat loops allow a block to loop while or until a condition is met.
The count with block loops from one number to another by a specified side increment.
The for each loop iterates through values in a list.
Loop termination blocks exit the block or skip an iteration when a condition is met.
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Sign in for the best experience
Save your progress
Get access to courses
Receive personalized recommendations
May we collect and use your data?
Learn more about the Third Party Services we use and our Privacy Statement.May we collect and use your data to tailor your experience?
Explore the benefits of a customized experience by managing your privacy settings for this site or visit our Privacy Statement to learn more about your options.