Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

exit() function

exit() function

exit() function

What is the command to break out of the present if statement or for loop, etc. I've tried 'exit' but it exits the whole program.

RE: exit() function

You can use something like a next if statement.

The syntax would be

next if (some statement) {
# what ever you want to happen


So say if you have a for loop that says:

for ($i=0;$i<40;$i++) {

# do something
# but say that if you need to exit before it gets to 39, then you write:

next if ($i=20) {




so it goes to somesub if $i equals 20.

Hope this helps.


RE: exit() function

works like this:

while(1){ # loop forever in other words
  $i ++;
  next if $i < 3; # jumps back to 'while',
  last if $i == 3; # jumps out of 'while' loop

would work the same without the 'next if' line -- just wanted to show what it does

Cargill's Corporate Web Site

RE: exit() function

Thank you very much mike and vik.It worked fine.

RE: exit() function

hello vikter,
  here is some loop control constructs which will be very useful to u
 last - stop the execution of the loop,and continues with
         the next statement after the loop (like break in C)
 next - Stops the current iteration of the loop , goes back
         to the top and starts continues with the next value
        of the loop index variable( in for loop).
        it is very useful method (like continue in C )
 redo - Stops the current execution and goes to the top and
         "restart" the loop revaluating the test .

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close