Posted: Sun May 22, 2011 2:50 pm Post subject: RE:[tutorial] loops and faking goto line
@Raknarg -- that only works with a very limited number of (condition)s (as you'd have to write out all of the elseif paths yourself), and if all of the condition values are known ahead of time.
E.g.: (condition)'s value is obtained during the execution of stuff() in a non-deterministic way (such as user input).
Posted: Sun May 22, 2011 4:48 pm Post subject: RE:[tutorial] loops and faking goto line
Yeah, that's why I like fake goto lines better
mirhagk
Posted: Tue May 24, 2011 4:41 pm Post subject: Re: RE:[tutorial] loops and faking goto line
Raknarg @ Sun May 22, 2011 2:18 pm wrote:
Well, there's different ways to do it. The way my teacher is telling me to do it is just by using an if statement.
Instead of:
Turing:
loop
stuff
exitwhen(condition)
more stuff
exit endloop
You could use:
Turing:
if(condition)then
stuff
else
stuff
more stuff
endif
Get it?
Um How about the ultra simple:
Turing:
stuff
if(notcondition)then
more stuff
endif
I would say that's much cleaner than both options, with less lines of code.
2goto1
Posted: Tue May 24, 2011 4:54 pm Post subject: Re: RE:[tutorial] loops and faking goto line
mirhagk @ Tue May 24, 2011 4:41 pm wrote:
Um How about the ultra simple:
Turing:
stuff
if(notcondition)then
more stuff
endif
I would say that's much cleaner than both options, with less lines of code.
I agree. For increased readability, as a general best practice in all languages, I like to try to name boolean variables with names that imply a positive value. It makes boolean comparisons more readable because you avoid double negatives. For example, the code below tests if someone is of legal driving age:
Turing:
var isNotLegalDrivingAge :boolean:=false if(not isNotLegalDrivingAge)then % The person if of legal driving age endif
It can get messy when you start to code logic containing lots of these double negative conditions. Instead, name your boolean variables with names that imply a positive condition, such as the following:
Turing:
var isLegalDrivingAge :boolean:=false if(isLegalDrivingAge)then % The person if of legal driving age endif
Hoshi
Posted: Sun Dec 18, 2011 2:26 pm Post subject: RE:[tutorial] loops and faking goto line
I like your Review on loops . It is very helpful for test review! It goes well with Cervantes Loops Tutorial too