Current Page:
NeXtMidas Training
Macros - Part 1 (Basics)
Loops and Control Structures
Lab 1 - Macro Control
Instructions
|
|
- Lab 1 - Macro Control (Instructions):
- Using a text editor, create a new file named
contlab1.mm
in the mcr area of the TRAIN option tree (this is the
option tree you created in Lab 2 - Option Trees).
- Your macro will take in one parameter
TAB= which
will be a table.
- Inside the body of the macro will be three loops:
- Loop 1:
- Create a counting loop that counts by-threes from -9 to 9.
- Inside this loop you will need to add a conditional that
has three blocks in it (
IF , ELSEIF ,
and ELSE ).
- Your conditional should check to see if the current count is
zero, even or odd and should print out a message telling the
current count and whether it is zero, odd or even.
- Hint: Before the
IF you can
use CALCULATOR to compute
x = (count mod 2) ; by doing
this you will know if the count is even (x=0).
- Loop 2:
- This loop is more complicated than the first loop and will
require a little bit of code before the loop to set things
up.
- In this loop you will be asked to convert between nautical miles
(nmi) and kilometers (km). So the first thing you need to do
is set up the conversion factor (
NM2KM ).
- NeXtMidas already has the conversion from nautical miles
to meters in its set of constants. You will need to use
INVOKE to get the value of
nxm.sys.inc.Constants.NM2METERS .
- Once you have the value of
NM2METERS you
can use calculator to convert this to NM2KM
(if you remember back to high school, you will recall
that there are 1000 meters in a kilometer, so this is
just a simple division using CALCULATOR ).
- Starting with 0nmi you will need to print out the conversion
of nautical miles (nmi) to kilometers (km) for all integer
values of nmi where km is less than ten.
- Hint: You can initially start with 0nmi=0km.
- Loop 3:
- This is an easy loop.
- Just loop through the keys in the table that was passed in and
print out the key and the value it corresponds with.
- When you are done use
UPDATE to add your macro to the
dictionary and try it out. The output should look similar to this:
nM> contlab1 {A=1,B=2,C=3}
Count is -9 (odd)
Count is -6 (even)
Count is -3 (odd)
Count is 0 (zero)
Count is 3 (odd)
Count is 6 (even)
Count is 9 (odd)
0nmi = 0.0km
1nmi = 1.852km
2nmi = 3.704km
3nmi = 5.556km
4nmi = 7.408km
5nmi = 9.26km
KEY=A VALUE=1
KEY=B VALUE=2
KEY=C VALUE=3
|
|
|