Going back to beginning of code

I was wondering if there is a way of going back to a specific line in the code. I want to go from line 66 to line 30. Is there a way of doing this? Thanks.

EDIT: I have edited the code but I still need to go back to the beginning (line 78). Is there a way of doing this? Thanks.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Test::Test() {
    
    double CrL;
    double L,tempL;
    double enterPx,enterPy,enterPz;    
    bool foo;
    
    
    DistanceToShell A1;
    ComptonScattering C1;
    CrIntersectionLength C2;
    CrIntersectionLength C3; // to keep track of entering point
    
    A1.GetPosition(s,phi,z,theta2,phi2);
    A1.ComptonCalculation(get.WalloyCompton(energy-100));
    
    L = A1.ComptonCalculation(get.WalloyCompton(energy-100)); // 
    
    Px = A1.PointX();
    Py = A1.PointY();
    Pz = A1.PointZ();
    
    //Random position inside Rod in cartesian coordinates
    pointx = s*cos(phi) + s_1*cos(phi_1);
    pointy = s*sin(phi) + s_1*sin(phi_1); 
    pointz = z + z_1;
    
    // Rod is chosen above
    // poin(x,y,z) is Rod position (z = 0)
    
    foo = check(Px,pointx,Py,pointy,Pz,pointz,ChromiumRadius());
    
    if (foo==true) { // gamma compton scattered within initial rod
        ComptonScattering_True(); // re-defines s,phi,z,theta2,phi2, and energy.
        // go back to beginning
    }
    
    else if (foo==false) { // gamma not yet compton scattered within initial rod
        
        AssignToRods(pointx,pointy,pointz); // Sort rods closest - farthest
        
        //C2.GetFirstRandom(s,phi,z);
        //C2.GetFirstCylinder(s_1,phi_1,z_1);
        //C2.GetSecondCylinder(s_1,phi_1,z_1);
        //C2.GetLPoints(Px,Py,Pz);
        //C2.Calculations();
        
        C3.GetFirstRandom(s,phi,z);
        C3.GetFirstCylinder(Rods[myvector.at(0)].at(0),Rods[myvector.at(0)].at(1),Rods[myvector.at(0)].at(2));
        C3.GetSecondCylinder(Rods[myvector.at(0)].at(0),Rods[myvector.at(0)].at(1),Rods[myvector.at(0)].at(2));
        C3.GetLPoints(20.,20.,20.); // any number >= 20
        C3.Calculations();
        
        CrL = C3.fIntersectionLength();
        
        L = L - CrL;
        
        for (int i=0; i<SortedRods.size(); i++) {
            
            C3.GetFirstRandom(s,phi,z);
            C3.GetFirstCylinder(Rods[myvector.at(0)].at(0),Rods[myvector.at(0)].at(1),Rods[myvector.at(0)].at(2));
            C3.GetSecondCylinder(Rods[myvector.at(i+1)].at(0),Rods[myvector.at(i+1)].at(1),Rods[myvector.at(i+1)].at(2));
            C3.GetLPoints(20.,20.,20.);
            C3.Calculations();
            
            if (C3.btClose()==false) {
                if (C3.btFar()==false) {
                    CrL = C3.fIntersectionLength();
                    L = L - CrL;
                    
                    if (L==0); // store initial energy and exit Test
                    double magnitude;
                    magnitude = sqrt(pow(Px,2)+pow(Px,2)+pow(Px,2));
                    if (magnitude > 15); // store initial and final energy and exit Test
                }
                else if (C3.btFar()==true) {
                    ComptonScattering_True(); // re-defines s,phi,z,theta2,phi2, and energy.
                    // go back to beginning from here
                }
            }
            else if (C3.btClose()==true); // going into W
        }
    }
}

Last edited on
Seems like you make an infinite loop if you do that. Line 30 makes foo false, so going back to it will have you always enter the if statement.
I have edited the previous code LowestOne. Assist please ;)
closed account (o3hC5Di1)
Hi there,

Are you looking for something like this: www.cplusplus.com/doc/tutorial/control/#goto

Please note that opinions are divided one whether it is a good idea or not to use goto.
In a lot of cases it can be solved by creating a function that isolates the logic you are trying to re-use.

Hope that helps.

All the best,
NwN
Last edited on
It seems I can use goto.But like you said, I think I'll isolate the first part and go from there. Thanks NwN!

Last edited on
Topic archived. No new replies allowed.