### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: How to determine if a result is an integer? [SOLVED]  (Read 15063 times)

#### BobDog

• Full Member
• Posts: 168
##### Re: How to determine if a result is an integer?
« Reply #45 on: September 07, 2021, 12:17:57 pm »
@BobDog,
Regarding your extensive use of goto statement instead of else clauses - I am just curious, have you started programming on a Basic language?
. . .
. . .

Hello y.ivanov.
I have no problems using goto in pascal, with all variables already having been set, there is no chance of passing across variable creations.
However in basic care must be taken in this regard.
I could of course use clauses as you say, but I find them cumbersome and bloaty when a simple goto does the job.
I just like to get a task done.
Basic and pascal being educational languages, pascal more for modular programming, I started both in the 1970's, but I have only recently returned to pascal via this forum, so I am still a little bit twitchy here.
I have been using freebasic for many years as a hobby coder, that's all I do regarding computers - a hobby.
Thanks.

#### BornAgain

• New Member
• Posts: 34
##### Re: How to determine if a result is an integer?
« Reply #46 on: October 15, 2021, 08:14:48 pm »
Thanks to the many who contributed to answering this question. I need to do a little more work in this project and now have a question related to the same general project and so thought I'd post it right here. I remember having read somewhere that it is not good form to use "break" in a program, but I don't know what else I can use in this context. Worse, "break" seems to be misbehaving! This is what is happening:

I have a number of DNA sequences in a file. For each of them (a string) I needed to find a substring that begins with "ATG" and ends with "TGA," "TAG" or "TAA" in the same frame (that is, if you count triplets of letters, the final three need to be one of the three: "TGA," "TAG" or "TAA." So the length of the string needs to be a multiple of 3. Thanks to your help, I have found such a substring for each sequence. Let us say that for the first sequence, I have found a substring that ends with TGA. Now, I need to find if there are any "TGAs," "TAGs" or "TAAs" nested within the sequence in the same frame. If there is even one, the substring is of no use and I need to move to the next ATG in the DNA sequence and find the substring that begins with this ATG and ends with one of the three termination triplets. Without going into the actual code, I have this nested loop structure:

Code: Pascal  [Select][+][-]
1. for I := 0 to SequenceFile - 1 do //SequenceFile is a TStringList
2. begin
3.    .
4.    .
5.    .
6.    for J := 1 to NumATGs do //NumATGs is the number of ATGs in the Ith sequence
7.    begin
8.       //here I find the sequence that meets the criteria of beginning with ATG and ending with TGA
9.       .
10.       .
11.       .
12.       //here I am looking for any nested TGAs (except for the last three which are already TGA). If I find one, then I need to get out of this loop and move to the next where I need to find any nested TAGs.
13.       PosTGA := Pos('TGA', TryORF) + 3;//TryORF is a substring that begins with ATG and ends with one of three termination triplets
14.       for K := 1 to NumTGAs_Temp do
15.       begin
16.          if (PosTGA < lenTryORF) then //if the TGA is in the middle and not the end of the ORF; lenTryORF is the length of TryORF
17.          begin
18.             if ((PosTGA - 1) mod 3 = 0) then //if there is a nested ORF then move to next ATG
19.                break
20.             else PosTGA := PosEx('TGA', TempStr, PosTGA) + 3;//see if the next TGA is nested
21.          end
22.          else PosTGA := PosEx('TGA', TempStr, PosTGA) + 3;
23.       end;
24.
25.       //here I am looking for any nested TAGs (just like above).
26.       PosTAG := Pos('TAG', TryORF) + 3;
27.       for K := 1 to NumTAGs_Temp do
28.       begin
29.          if (PosTAG < lenTryORF) then //if the TAG is in the middle and not the end of the ORF
30.          begin
31.             if ((PosTAG - 1) mod 3 = 0) then //if there is a nested ORF then move to next ATG
32.                break
33.             else PosTAG := PosEx('TAG', TempStr, PosTAG) + 3;
34.          end
35.          else PosTAG := PosEx('TAG', TempStr, PosTAG) + 3;
36.       end;
37.
38.
39.       //here I am looking for any nested TAAs (just like above).
40.       PosTAA := Pos('TAA', TryORF) + 3;
41.       for K := 1 to NumTAAs_Temp do
42.       begin
43.          if (PosTAA < lenTryORF) then //if the TAA is in the middle and not the end of the ORF
44.          begin
45.             if ((PosTAA - 1) mod 3 = 0) then //if there is a nested ORF then move to next ATG
46.                break
47.             else PosTAA := PosEx('TAA', TempStr, PosTAA) + 3;
48.          end
49.          else PosTAA := PosEx('TAA', TempStr, PosTAA) + 3;
50.       end;
51.
52.
53.    end;
54. end;
55.

By the way, If my program finds a nested termination codon (say TGA in the first loop for index K) it is supposied to break from that loop and move to the next ATG in the sequence (that is the J loop) or move to the next K loop (to look for any nested TAGs. Instead, it moves to the I loop, abandoning the current sequence and moving to the next sequence in the file.

What am I doing wrong?

#### jamie

• Hero Member
• Posts: 5027
##### Re: How to determine if a result is an integer?
« Reply #47 on: October 15, 2021, 11:30:55 pm »
all I can offer is this..

1. You have a "TRY" just prior to the code that is aborting. In this case the BREAK will go to the "FINALLY" skipping all.

2. It's not clear via DOCs how this is suppose to go off when a BREAK is encountered in nested FOR LOOPS. I am sure it suppose to only

3. Possible a compiler bug ?

4. you have over looked something ?
The only true wisdom is knowing you know nothing

#### BornAgain

• New Member
• Posts: 34
##### Re: How to determine if a result is an integer?
« Reply #48 on: October 16, 2021, 12:00:09 am »
@jamie, you got it right in your first educated guess! I did indeed have a "Try..finally..end" in my program and all the code was nested between the Try and Finally. I removed it and now the program nicely skips over to the next K loop when it encouters a nested termination triplet. So thank you!

Since I'm not terribly familiar with the ettiquette of the forum, am I supposed to somehow acknowledge when my question was answered? I mean, apart from a "thank you." If there is, I'd be happy to do it.
« Last Edit: October 16, 2021, 12:02:31 am by BornAgain »

#### jamie

• Hero Member
• Posts: 5027
##### Re: How to determine if a result is an integer?
« Reply #49 on: October 16, 2021, 12:20:26 am »
if you think all is solved then you can go back to your original post, the first one of this thread and modify the post subject line.

for example [Solved] along with the original text etc.

The only true wisdom is knowing you know nothing

#### BornAgain

• New Member
• Posts: 34
##### Re: How to determine if a result is an integer?
« Reply #50 on: October 27, 2021, 09:21:46 pm »
Thank you. Will do, but I thought there was a way to acknowledge that your answer helped. Anyway, sorry for the delay in replying.