Reputation: 26428
Is there any way of executing the already executed code in java.
for example in the main method i have int variable a = 10; and later point in time say suppose at the end of execution i will check some conditions on its(a's) value and if the condition fails then i want it to execute from the beginning.
there may be some other scenarios also, right now i have this.
Edit: without looping and methods. which i know. like goto statements in c++. and dont think only for the above stated example there might be some other example which might need the way i wanted.
Upvotes: 0
Views: 264
Reputation: 7760
The correct answer is: No, there is no way to do that in Java. You would have to use a loop or recursive method.
Upvotes: 1
Reputation: 90543
why can't you just do something like this?
do {
a = processSomething();
} while(a != 10);
EDIT: if you can't use a proper loop construct, then recursion is your only real choice.. something like this:
int rFunction(int a) {
// if we found our needed value, return it
if(a == 10) {
return a;
}
a = whatever();
rFunction(a); // call again with new value
}
Upvotes: 4