Jump to content
Mr. Carlos Repolho

simple if..else struc problem

Recommended Posts

if (Lratio < 1)

 

Lfn.setvalue(Los)

 

elseif (Lratio >= 1.1)

 

Lfn.setvalue(1.0667*L)

 

else

 

Lfn.setvalue(L + (2/3)*(Los - L))

 

endif

 

For some reason for a Lratio =1.05, the code jumps the else command and attributes zero to Lfn.

 

Also if i would like to ask in another case if i would want to write something like this:

 

elseif( 1=<Lratio<1.1) .. could it be done like: elseif ( and ( Lratio>=1,Lration<1.1))

 

best regards 

 

 

 

Share this post


Link to post
Share on other sites

HI Carlos,

the jump to else seems reasonable since 1.05 is neither smaller than 1 nor larger than 1.1. It is a bit difficult to understand why Lfn comes out as zero if exept for Los= -0.5 x L

Cheers

Claus

Share this post


Link to post
Share on other sites

Good morning 

 

I also dont understant why it jumps the else Claus.

 

Stefan can you give me a simple example how to use the and structure in this case, i already tried it before but it didnt work.

 

best regards

Share this post


Link to post
Share on other sites

Hi Carlos,

 

what do you mean by "jumps the else", does it run into the else case if Lratio == 1.05?

The "and" statement works like this:

 

if (Lratio < 1)

 

Lfn.setvalue(Los)

 

elseif (Lratio >= 1.1)

 

Lfn.setvalue(1.0667*L)

 

elseif ( and ( Lratio>=1, Lratio<1.1))

 

Lfn.setvalue(L + (2/3)*(Los - L))

 

endif

 

But that does not make any sense since "and ( Lratio>=1,Lratio<1.1)" is implicit for the else case in your example.

 

Cheers,

Stefan

Share this post


Link to post
Share on other sites

"But that does not make any sense since "and ( Lratio>=1,Lratio<1.1)" is implicit for the else case in your example"

 

Yes i thought it would be implicit due to the value 1.05 complies with the inner interval, but for some reason it jumps of the 'else '  and doesn't attribute any value to Lfn.

 

Anyway i will try the and command and then after i will  upload the file so you could take a look if you have some spare time.

 

This is a feature for a simple empirical method of resistance prediction called Hollenbach, in the beginning of the code i need to define this Lfn which depends on a ratio that is obtained by (Los/lpp), after the Fn is calculated and the prediction is made.

 

After this code i still need to do Holtrop&Mennen and the EEDI so i was really needing some help in this :)

 

best regards

 

Thanks again!

Share this post


Link to post
Share on other sites

For debugging purpose, you could add some "echo" commands, to see which branch it really takes (you will see the output in console):

 

if (Lratio < 1)

    echo("Lratio < 1: " + Lratio)

    Lfn.setvalue(Los)

elseif (Lratio >= 1.1)

    echo("Lratio >= 1.1: " + Lratio)

    Lfn.setvalue(1.0667*L)

else

    echo("else branch: " + Lratio)

    Lfn.setvalue(L + (2/3)*(Los - L))

endif

 

Cheers,

Stefan

Share this post


Link to post
Share on other sites

I saw the tutorial and i thought about doing it, will do it as soon as i leave work. doing my thesis while working at a shipyard has become a much bigger challenge than i was prospecting... :wacko:

 

When i have some results i will post here.

 

Danke Stefan

Share this post


Link to post
Share on other sites

Hi !

 

Something strange its happening! The code works and it worked with what i had written before but when debugging if i don't put the break point exactly on the else, Lfn variable it jumps and for the porpuse of debugging the user cant see any change.

 

I think is something about the debugger so if i could send the feature to you i think it would be usefull.

 

best regards and thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...