Go to a line of code , skip few lines of code

Hi ,

I have a code where i am using a infinite while loop . some thing like below

while [ 2 -gt 1 ]
do

if [ logic ]
then
#go to line 20 

fi
command 1;


command 2;

#line 20:
sleep 34;
done;

Now i want that if my logic enters the if loop it should go directly to sleep 34 ; and i.e. skip command 1 and command 2 .

Can anyone suggest something .

There are 2 options:

  1. Call a function that runs sleep command
sleep_func()
{
  sleep 34
}
if [ logic ]
then
 sleep_func
fi
  1. Call sleep inside the if condition itself:-
if [ logic ]
then
 sleep 34
fi

Hi bipinajith,

Thanks for yur response but i want to move to line of code of 34 , i am doing a lot of calculations in command 1 and command 2 , I just want to skip these 2 lnes of code and move to line 20 as in my code ...

so above 2 suggestions wont solve my problem , please suggest if you can advice on something which skips command 1 and command 2

Regards

I don't think there is goto statement available in most shells except for tcsh But using it is considered as a bad programming practice.

Why don't you put the commands inside the else construct of if statement?

if [ logic ]
then
 sleep 34
else
 command 1
 command 2
fi
1 Like

Hi ,

Yes , i know its a bad programming practice but i was trying to find it out on bash , may be its not available on bash .

I am sure , if / else will solve this .

Thank You :slight_smile:
Paarth

if [ logic ]
then
  sleep 34
  continue
fi