BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted
Community Trekker

## How do I exit the loop when something is satisfied?

After the data table is sorted by the age column in ascending order, the cycle is conducted by the age column. When the age is equal to the age of the previous row, n=n+1, otherwise, the cycle is withdrawn.Thank you!

dt = Open( "\$SAMPLE_DATA\Big class.jmp" );
r = N Row( dt );
n = 0;
For( i == 2, i <= r, i++,
If( dt[i - 1, "age"] = dt[i, "age"],
n = n + 1,
stop loop
);

);

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How do I exit the loop when something is satisfied?

You want the BREAK command.  From the scripting index:

``````Names Default To Here( 1 );
For( i = 1, i <= 10, i++,
If( i == 5, Break() );
Print( "i=" || Char( i ) );
);``````
1 REPLY 1
Super User

## Re: How do I exit the loop when something is satisfied?

You want the BREAK command.  From the scripting index:

``````Names Default To Here( 1 );
For( i = 1, i <= 10, i++,
If( i == 5, Break() );
Print( "i=" || Char( i ) );
);``````